[Fixes #6322] Supporting multiple scopes/contexts in .po file entries.

This commit is contained in:
Piotr Szmyd
2016-01-31 18:22:33 +01:00
parent 899379e94a
commit 52668d1beb

View File

@@ -14,17 +14,19 @@ namespace Orchard.Localization.Services {
};
public void ParseLocalizationStream(string text, IDictionary<string, string> translations, bool merge) {
StringReader reader = new StringReader(text);
string poLine, id, scope;
id = scope = String.Empty;
var reader = new StringReader(text);
string poLine;
var scopes = new List<string>();
var id = string.Empty;
while ((poLine = reader.ReadLine()) != null) {
if (poLine.StartsWith("#:")) {
scope = ParseScope(poLine);
scopes.Add(ParseScope(poLine));
continue;
}
if (poLine.StartsWith("msgctxt")) {
scope = ParseContext(poLine);
scopes.Add(ParseContext(poLine));
continue;
}
@@ -34,20 +36,24 @@ namespace Orchard.Localization.Services {
}
if (poLine.StartsWith("msgstr")) {
string translation = ParseTranslation(poLine);
var translation = ParseTranslation(poLine);
// ignore incomplete localizations (empty msgid or msgstr)
if (!String.IsNullOrWhiteSpace(id) && !String.IsNullOrWhiteSpace(translation)) {
string scopedKey = (scope + "|" + id).ToLowerInvariant();
if (!translations.ContainsKey(scopedKey)) {
translations.Add(scopedKey, translation);
}
else {
if (merge) {
translations[scopedKey] = translation;
if (!string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(translation)) {
foreach (var scope in scopes) {
var scopedKey = (scope + "|" + id).ToLowerInvariant();
if (!translations.ContainsKey(scopedKey)) {
translations.Add(scopedKey, translation);
}
else {
if (merge) {
translations[scopedKey] = translation;
}
}
}
}
id = scope = String.Empty;
id = string.Empty;
scopes = new List<string>();
}
}