mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +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:
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
@@ -166,6 +167,46 @@ namespace Orchard.Localization.Services {
|
|||||||
return translations;
|
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) {
|
private static void ParseLocalizationStream(string text, IDictionary<string, string> translations, bool merge) {
|
||||||
StringReader reader = new StringReader(text);
|
StringReader reader = new StringReader(text);
|
||||||
string poLine, id, scope;
|
string poLine, id, scope;
|
||||||
@@ -202,15 +243,15 @@ namespace Orchard.Localization.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static string ParseTranslation(string poLine) {
|
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) {
|
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) {
|
private static string ParseScope(string poLine) {
|
||||||
return poLine.Substring(2).Trim().Trim('"');
|
return Unescape(poLine.Substring(2).Trim().Trim('"'));
|
||||||
}
|
}
|
||||||
|
|
||||||
class CultureDictionary {
|
class CultureDictionary {
|
||||||
|
|||||||
Reference in New Issue
Block a user