Skip to content

Commit

Permalink
Merge pull request #46 from MiguelDomingues/fix-keeptogether-translation
Browse files Browse the repository at this point in the history
Fix issue with translating with --keep-literals-together
  • Loading branch information
MiguelDomingues authored Oct 4, 2023
2 parents 971377e + 13e3cf9 commit f31b88c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ private void WriteMultipleTogether(IEnumerable<Inline> childs, int index)
if (transformedS == null)
throw new Exception("Missing translation for: " + str);

MoveTo(startIndex);

Write(trimStart);
Write(transformedS);
Write(trimEnd);
Expand Down
19 changes: 19 additions & 0 deletions test/MarkdownLocalize.Tests/TranslateMarkdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void TranslateKeepSource()
[Fact]
public void Quote()
{
MarkdownParser.SetParserOptions(new RendererOptions());
var catalog = POT.Load(ReadPO("headings.pt-PT.po"));
TranslationInfo info;
string md = POT.Translate(catalog, @"- Heading
Expand All @@ -87,6 +88,7 @@ public void Quote()
[Fact]
public void QuoteTwo()
{
MarkdownParser.SetParserOptions(new RendererOptions());
var catalog = POT.Load(ReadPO("headings.pt-PT.po"));
TranslationInfo info;
string md = POT.Translate(catalog, @"- Heading
Expand All @@ -107,6 +109,7 @@ public void QuoteTwo()
[Fact]
public void ListWithIndentedText()
{
MarkdownParser.SetParserOptions(new RendererOptions());
var catalog = POT.Load(ReadPO("headings.pt-PT.po"));
TranslationInfo info;
string md = POT.Translate(catalog, @"1. Heading
Expand Down Expand Up @@ -136,4 +139,20 @@ 1. Título
Assert.Equal(7, info.TranslatedCount);
}

[Fact]
public void MultipleLiteralsTogetherImage()
{
MarkdownParser.SetParserOptions(new RendererOptions()
{
KeepLiteralsTogether = true,
});
var catalog = POT.Load(ReadPO("headings.pt-PT.po"));
TranslationInfo info;
string md = POT.Translate(catalog, @"![Hello](image.png)", null, null, true, out info);

Assert.Equal(@"![Olá](image.png)", md);

Assert.Equal(1, info.TotalCount);
Assert.Equal(1, info.TranslatedCount);
}
}
4 changes: 4 additions & 0 deletions test/MarkdownLocalize.Tests/resources/headings.pt-PT.po
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ msgstr "Olá\nMundo"
msgctxt "Image alternative text"
msgid "Hello"
msgstr "Olá"

msgctxt "Text"
msgid "Hello"
msgstr "Olá"

0 comments on commit f31b88c

Please sign in to comment.