mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
- culture fallback to parent/neutral when resolving localized strings.
--HG-- branch : dev
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
@@ -44,13 +45,39 @@ namespace Orchard.Localization.Services {
|
||||
if (culture.Translations.ContainsKey(genericKey)) {
|
||||
return culture.Translations[genericKey];
|
||||
}
|
||||
return text;
|
||||
|
||||
return GetParentTranslation(scope, text, cultureName);
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private string GetParentTranslation(string scope, string text, string cultureName) {
|
||||
string scopedKey = scope + "|" + text;
|
||||
string genericKey = "|" + text;
|
||||
try {
|
||||
CultureInfo cultureInfo = CultureInfo.GetCultureInfo(cultureName);
|
||||
CultureInfo parentCultureInfo = cultureInfo.Parent;
|
||||
if (parentCultureInfo.IsNeutralCulture) {
|
||||
foreach (var culture in _cultures) {
|
||||
if (String.Equals(parentCultureInfo.Name, culture.CultureName, StringComparison.OrdinalIgnoreCase)) {
|
||||
if (culture.Translations.ContainsKey(scopedKey)) {
|
||||
return culture.Translations[scopedKey];
|
||||
}
|
||||
if (culture.Translations.ContainsKey(genericKey)) {
|
||||
return culture.Translations[genericKey];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CultureNotFoundException) { }
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private void LoadCultures() {
|
||||
foreach (var culture in _cultureManager.ListCultures()) {
|
||||
_cultures.Add(new CultureDictionary {
|
||||
|
||||
Reference in New Issue
Block a user