Skip to content

Commit

Permalink
fix: Better support for phrases which contain a \n (#176)
Browse files Browse the repository at this point in the history
* Better support for phrases which contain a \n

* Removed temporary test
  • Loading branch information
LinusCenterstrom authored Nov 6, 2024
1 parent d285307 commit 7dffc11
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<OutputType>Exe</OutputType>
<StartupObject>MN.L10n.BuildTasks.Program</StartupObject>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>4.0.0</Version>
<Version>4.0.1</Version>
<Authors>Chris Gårdenberg</Authors>
<Company>MultiNet Interactive AB</Company>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageProjectUrl>https://github.com/MultinetInteractive/MN.L10n</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<Copyright>© 20XX MultiNet Interactive AB</Copyright>
<Version>3.0.1</Version>
<Version>3.0.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MN.L10n.Javascript.Shared/MN.L10n.Javascript.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageProjectUrl>https://github.com/MultinetInteractive/MN.L10n</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<Copyright>© 20XX MultiNet Interactive AB</Copyright>
<Version>2.0.0</Version>
<Version>2.0.1</Version>
<AutoIncrementPackageRevision>True</AutoIncrementPackageRevision>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions MN.L10n.Javascript/MN.L10n.Javascript.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>net48</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0</Version>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<Version>2.0.1</Version>
<AssemblyVersion>2.0.0.1</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 11 additions & 1 deletion MN.L10n.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.IO;
using System.Linq;
using Xunit;

namespace MN.L10n.Tests
Expand Down Expand Up @@ -105,5 +106,14 @@ public void TestWorksWithLiteralTemplateStrings()
var result = parser.Parse(src);
Assert.Single(result);
}

[Fact]
public void LineBreakCharInCall()
{
var parser = new L10nParser();
var result = parser.Parse("_s('Hello\\nBrother')");

Assert.Collection(result, x => Assert.Equal("Hello\nBrother", x.Phrase));
}
}
}
10 changes: 9 additions & 1 deletion MN.L10n/L10nParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,15 @@ bool TryPeek(int forward)
}
}

_tokenContent.Append(source[_pos]);
if (inToken && !isVerbatim && source[_pos] == '\\' && TryPeek(1) && source[_pos + 1] == 'n')
{
_pos++;
_tokenContent.Append('\n');
}
else
{
_tokenContent.Append(source[_pos]);
}
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions MN.L10n/MN.L10n.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Translation package</Description>
<PackageProjectUrl>https://github.com/MultinetInteractive/MN.L10n</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<Copyright>© 20XX MultiNet Interactive AB</Copyright>
<Version>4.0.0</Version>
<Version>4.0.1</Version>
<AutoIncrementPackageRevision>True</AutoIncrementPackageRevision>
<PackageReleaseNotes>Now includes analyzer</PackageReleaseNotes>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject></StartupObject>
<AssemblyVersion>4.0.0</AssemblyVersion>
<AssemblyVersion>4.0.1</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down

0 comments on commit 7dffc11

Please sign in to comment.