mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
- Resource manager processes po files, scope fallback.
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Orchard.FileSystems.WebSite;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
@@ -19,11 +21,21 @@ namespace Orchard.Localization.Services {
|
||||
LoadCultures();
|
||||
}
|
||||
|
||||
if (cultureName.Equals("en-US")) {
|
||||
return text;
|
||||
foreach (var culture in _cultures) {
|
||||
if (String.Equals(cultureName, culture.CultureName, StringComparison.OrdinalIgnoreCase)) {
|
||||
string scopedKey = scope + "|" + text;
|
||||
string genericKey = "|" + text;
|
||||
if (culture.Translations.ContainsKey(scopedKey)) {
|
||||
return culture.Translations[scopedKey];
|
||||
}
|
||||
if (culture.Translations.ContainsKey(genericKey)) {
|
||||
return culture.Translations[genericKey];
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
return text;
|
||||
}
|
||||
|
||||
private void LoadCultures() {
|
||||
@@ -38,16 +50,65 @@ namespace Orchard.Localization.Services {
|
||||
private IDictionary<string, string> LoadTranslationsForCulture(string culture) {
|
||||
string path = string.Format(CoreLocalizationFilePathFormat, culture);
|
||||
string text = _webSiteFolder.ReadFile(path);
|
||||
return ParseLocalizationStream(text);
|
||||
if (text != null) {
|
||||
return ParseLocalizationStream(text);
|
||||
}
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
private static IDictionary<string, string> ParseLocalizationStream(string text) {
|
||||
return new Dictionary<string, string>();
|
||||
Dictionary<string, string> translations = new Dictionary<string, string>();
|
||||
StringReader reader = new StringReader(text);
|
||||
string poLine, id, scope;
|
||||
id = scope = String.Empty;
|
||||
while ((poLine = reader.ReadLine()) != null) {
|
||||
if (poLine.StartsWith("#:")) {
|
||||
scope = ParseScope(poLine);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (poLine.StartsWith("msgid")) {
|
||||
id = ParseId(poLine);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (poLine.StartsWith("msgstr")) {
|
||||
string translation = ParseTranslation(poLine);
|
||||
if (!String.IsNullOrEmpty(id)) {
|
||||
if (!String.IsNullOrEmpty(scope)) {
|
||||
string scopedKey = scope + "|" + id;
|
||||
if (!translations.ContainsKey(scopedKey)) {
|
||||
translations.Add(scopedKey, translation);
|
||||
}
|
||||
}
|
||||
string genericKey = "|" + id;
|
||||
if (!translations.ContainsKey(genericKey)) {
|
||||
translations.Add(genericKey, translation);
|
||||
}
|
||||
}
|
||||
id = scope = String.Empty;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return translations;
|
||||
}
|
||||
|
||||
private static string ParseTranslation(string poLine) {
|
||||
return poLine.Substring(6).Trim().Trim('"');
|
||||
}
|
||||
|
||||
private static string ParseId(string poLine) {
|
||||
return poLine.Substring(5).Trim().Trim('"');
|
||||
}
|
||||
|
||||
private static string ParseScope(string poLine) {
|
||||
return poLine.Substring(2).Trim().Trim('"');
|
||||
}
|
||||
|
||||
class CultureDictionary {
|
||||
public string CultureName { get; set; }
|
||||
public IDictionary<string, string> Translations { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
class CultureDictionary {
|
||||
public string CultureName { get; set; }
|
||||
public IDictionary<string, string> Translations { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user