mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-15 12:41:17 +08:00
#16642: PO lines are now unescaped when parsed. Previously they weren't which also made the translation lookup fail since the scoped key didn't match.
Note: currently the orchard.core.po file is out of date and not working for other reasons --HG-- branch : dev
This commit is contained in:
parent
00579ede40
commit
c03c075082
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
@ -166,6 +167,46 @@ namespace Orchard.Localization.Services {
|
||||
return translations;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<char, char> _escapeTranslations = new Dictionary<char, char> {
|
||||
{ 'n', '\n' },
|
||||
{ 'r', '\r' },
|
||||
{ 't', '\t' }
|
||||
};
|
||||
|
||||
private static string Unescape(string str) {
|
||||
StringBuilder sb = null;
|
||||
bool escaped = false;
|
||||
for (var i = 0; i < str.Length; i++) {
|
||||
var c = str[i];
|
||||
if (escaped) {
|
||||
if (sb == null) {
|
||||
sb = new StringBuilder(str.Length);
|
||||
if (i > 1) {
|
||||
sb.Append(str.Substring(0, i - 1));
|
||||
}
|
||||
}
|
||||
char unescaped;
|
||||
if (_escapeTranslations.TryGetValue(c, out unescaped)) {
|
||||
sb.Append(unescaped);
|
||||
}
|
||||
else {
|
||||
// General rule: \x ==> x
|
||||
sb.Append(c);
|
||||
}
|
||||
escaped = false;
|
||||
}
|
||||
else {
|
||||
if (c == '\\') {
|
||||
escaped = true;
|
||||
}
|
||||
else if (sb != null) {
|
||||
sb.Append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb == null ? str : sb.ToString();
|
||||
}
|
||||
|
||||
private static void ParseLocalizationStream(string text, IDictionary<string, string> translations, bool merge) {
|
||||
StringReader reader = new StringReader(text);
|
||||
string poLine, id, scope;
|
||||
@ -202,15 +243,15 @@ namespace Orchard.Localization.Services {
|
||||
}
|
||||
|
||||
private static string ParseTranslation(string poLine) {
|
||||
return poLine.Substring(6).Trim().Trim('"');
|
||||
return Unescape(poLine.Substring(6).Trim().Trim('"'));
|
||||
}
|
||||
|
||||
private static string ParseId(string poLine) {
|
||||
return poLine.Substring(5).Trim().Trim('"');
|
||||
return Unescape(poLine.Substring(5).Trim().Trim('"'));
|
||||
}
|
||||
|
||||
private static string ParseScope(string poLine) {
|
||||
return poLine.Substring(2).Trim().Trim('"');
|
||||
return Unescape(poLine.Substring(2).Trim().Trim('"'));
|
||||
}
|
||||
|
||||
class CultureDictionary {
|
||||
|
Loading…
Reference in New Issue
Block a user