mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
[Fixes #6322] Supporting multiple scopes/contexts in .po file entries.
This commit is contained in:
@@ -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>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user