Skip to content

Commit e16c9e5

Browse files
committed
Fix multi-line parsing of PO files
1 parent 0899494 commit e16c9e5

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

NAPS2.Localization/LanguageContext.cs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,36 @@ public void Load(string poFile)
2222
using (var reader = new StreamReader(poFile))
2323
{
2424
string line;
25-
while ((line = reader.ReadLine()) != null)
25+
string NextLine() => line = reader.ReadLine()?.Trim();
26+
while (NextLine() != null)
2627
{
27-
line = line.Trim();
28-
if (line.StartsWith("msgid", StringComparison.InvariantCulture))
28+
if (!line.StartsWith("msgid", StringComparison.InvariantCulture))
2929
{
30-
var original = line.Substring(7, line.Length - 8);
31-
line = reader.ReadLine();
32-
if (line == null || !line.StartsWith("msgstr", StringComparison.InvariantCulture))
33-
{
34-
continue;
35-
}
36-
var translated = line.Substring(8, line.Length - 9);
37-
Strings[original] = new TranslatableString
38-
{
39-
Original = original,
40-
Translation = translated
41-
};
30+
continue;
4231
}
32+
33+
string original = line.Substring(7, line.Length - 8);
34+
while (NextLine() != null && line.StartsWith("\"", StringComparison.InvariantCulture))
35+
{
36+
original += line.Substring(1, line.Length - 2);
37+
}
38+
39+
if (line == null || !line.StartsWith("msgstr", StringComparison.InvariantCulture))
40+
{
41+
continue;
42+
}
43+
44+
string translated = line.Substring(8, line.Length - 9);
45+
while (NextLine() != null && line.StartsWith("\"", StringComparison.InvariantCulture))
46+
{
47+
translated += line.Substring(1, line.Length - 2);
48+
}
49+
50+
Strings[original] = new TranslatableString
51+
{
52+
Original = original,
53+
Translation = translated
54+
};
4355
}
4456
}
4557
}

0 commit comments

Comments
 (0)