Skip to content

Commit

Permalink
Fix parsing if default po header is added to po file (#1088)
Browse files Browse the repository at this point in the history
Fixes 1081
  • Loading branch information
Franklin89 authored and sebastienros committed Oct 11, 2017
1 parent 4c23b78 commit 9f26f1a
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,18 @@ public void Set(PoContext context, string text)
{
switch (context)
{
case PoContext.MessageId: MessageId = text; break;
case PoContext.MessageId:
{
// If the MessageId has been set to an empty string and now gets set again
// before flushing the values should be reset.
if (string.IsNullOrEmpty(MessageId))
{
_values.Clear();
}

MessageId = text;
break;
}
case PoContext.MessageContext: MessageContext = text; break;
case PoContext.Translation: _values.Add(text); break;
case PoContext.Text: AppendText(text); return; // we don't want to set context to Text
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# translator-comments
# translator-comments
#. extracted-comments
#: reference…
#, flag
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
msgctxt "OrchardCore.Localization"
msgctxt "OrchardCore.Localization"
msgid "Unknown system error"
msgstr "Error desconegut del sistema"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
msgid "Line:\t\"{0}\"\n"
msgid "Line:\t\"{0}\"\n"
msgstr "Line:\t\"{0}\"\n"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
msgid ""
msgid ""
"Here is an example of how one might continue a very long string\n"
"for the common case the string represents multi-line output."
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
msgid "book"
msgid "book"
msgid_plural "books"
msgstr[0] "kniha"
msgstr[1] "knihy"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
msgid "\"{0}\""
msgid "\"{0}\""
msgstr "\"{0}\""
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
msgctxt "
msgctxt "
msgid "Foo \"{0}\""
msgstr "Foo \"{0}\""
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"msgid "Unknown system error"
"msgid "Unknown system error"
"msgstr ""
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#. "File {0} does not exist"
#. "File {0} does not exist"
msgctxt "OrchardCore.FileSystems.Media.FileSystemStorageProvider"
msgid "File {0} does not exist"
msgstr "Soubor {0} neexistuje"
Expand Down
22 changes: 18 additions & 4 deletions test/OrchardCore.Tests/Localization/PoFiles/PoeditHeader.po
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
msgid ""
# Translation of kstars.po into Spanish.
# This file is distributed under the same license as the kdeedu package.
# Pablo de Vicente <pablo@foo.com>, 2005, 2006, 2007, 2008.
# Eloy Cuadra <eloy@bar.net>, 2007, 2008.
msgid ""
msgstr ""
"POT-Creation-Date: 2016-06-22 17:06+0200\n"
"PO-Revision-Date: 2016-08-01 11:57+0200\n"
"X-Poedit-Basepath: ../../..\n"
"Project-Id-Version: kstars\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2008-09-01 09:37+0200\n"
"PO-Revision-Date: 2008-07-22 18:13+0200\n"
"Last-Translator: Eloy Cuadra <eloy@bar.net>\n"
"Language-Team: Spanish <kde-l10n-es@kde.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"

msgid "Unknown system error"
msgstr "Error desconegut del sistema"
2 changes: 1 addition & 1 deletion test/OrchardCore.Tests/Localization/PoFiles/SimpleEntry.po
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
msgid "Unknown system error"
msgid "Unknown system error"
msgstr "Error desconegut del sistema"
23 changes: 19 additions & 4 deletions test/OrchardCore.Tests/Localization/PoParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,29 @@ public void ParseIgnoresEntryWithoutTranslation()
[Fact]
public void ParseIgnoresPoeditHeader()
{
// # Translation of kstars.po into Spanish.
// # This file is distributed under the same license as the kdeedu package.
// # Pablo de Vicente <pablo@foo.com>, 2005, 2006, 2007, 2008.
// # Eloy Cuadra <eloy@bar.net>, 2007, 2008.
// msgid ""
// msgstr ""
// "POT-Creation-Date: 2016-06-22 17:06+0200\n"
// "PO-Revision-Date: 2016-08-01 11:57+0200\n"
// "X-Poedit-Basepath: ../../..\n"
// "Project-Id-Version: kstars\n"
// "Report-Msgid-Bugs-To: http://bugs.kde.org\n"
// "POT-Creation-Date: 2008-09-01 09:37+0200\n"
// "PO-Revision-Date: 2008-07-22 18:13+0200\n"
// "Last-Translator: Eloy Cuadra <eloy@bar.net>\n"
// "Language-Team: Spanish <kde-l10n-es@kde.org>\n"
// "MIME-Version: 1.0\n"
// "Content-Type: text/plain; charset=UTF-8\n"
// "Content-Transfer-Encoding: 8bit\n"
// "Plural-Forms: nplurals=2; plural=n != 1;\n"

// msgid "Unknown system error"
// msgstr "Error desconegut del sistema"
var entries = ParseText("PoeditHeader");

Assert.Empty(entries);
Assert.True(entries.Count() == 1);
Assert.True(entries[0].Translations.Count() == 1);
}

[Fact]
Expand Down

0 comments on commit 9f26f1a

Please sign in to comment.