From d0306db0c33a032fbb26c74168489350f71b1ffa Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 11 Oct 2010 14:32:12 -0700 Subject: [PATCH 1/5] Theme localization files support --HG-- branch : dev --- .../Services/DefaultLocalizedStringManager.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Orchard/Localization/Services/DefaultLocalizedStringManager.cs b/src/Orchard/Localization/Services/DefaultLocalizedStringManager.cs index 6802f19a4..212acbd4c 100644 --- a/src/Orchard/Localization/Services/DefaultLocalizedStringManager.cs +++ b/src/Orchard/Localization/Services/DefaultLocalizedStringManager.cs @@ -17,6 +17,7 @@ namespace Orchard.Localization.Services { private readonly ISignals _signals; const string CoreLocalizationFilePathFormat = "~/Core/App_Data/Localization/{0}/orchard.core.po"; const string ModulesLocalizationFilePathFormat = "~/Modules/{0}/App_Data/Localization/{1}/orchard.module.po"; + const string ThemesLocalizationFilePathFormat = "~/Themes/{0}/App_Data/Localization/{1}/orchard.theme.po"; const string RootLocalizationFilePathFormat = "~/App_Data/Localization/{0}/orchard.root.po"; const string TenantLocalizationFilePathFormat = "~/App_Data/Sites/{0}/Localization/{1}/orchard.po"; @@ -109,6 +110,7 @@ namespace Orchard.Localization.Services { // In reverse priority order: // "~/Core/App_Data/Localization//orchard.core.po"; // "~/Modules//App_Data/Localization//orchard.module.po"; + // "~/Themes//App_Data/Localization//orchard.theme.po"; // "~/App_Data/Localization//orchard.root.po"; // "~/App_Data/Sites//Localization//orchard.po"; // The dictionary entries from po files that live in higher priority locations will @@ -124,17 +126,28 @@ namespace Orchard.Localization.Services { context.Monitor(_webSiteFolder.WhenPathChanges(corePath)); } - foreach (var module in _extensionManager.AvailableExtensions()) { - if (String.Equals(module.ExtensionType, "Module")) { + foreach ( var module in _extensionManager.AvailableExtensions() ) { + if ( String.Equals(module.ExtensionType, "Module") ) { string modulePath = string.Format(ModulesLocalizationFilePathFormat, module.Name, culture); text = _webSiteFolder.ReadFile(modulePath); - if (text != null) { + if ( text != null ) { ParseLocalizationStream(text, translations, true); context.Monitor(_webSiteFolder.WhenPathChanges(modulePath)); } } } + foreach ( var theme in _extensionManager.AvailableExtensions() ) { + if ( String.Equals(theme.ExtensionType, "Theme") ) { + string themePath = string.Format(ThemesLocalizationFilePathFormat, theme.Name, culture); + text = _webSiteFolder.ReadFile(themePath); + if ( text != null ) { + ParseLocalizationStream(text, translations, true); + context.Monitor(_webSiteFolder.WhenPathChanges(themePath)); + } + } + } + string rootPath = string.Format(RootLocalizationFilePathFormat, culture); text = _webSiteFolder.ReadFile(rootPath); if (text != null) { From 8a6f988ca097b3458d90f8df5ccbd4e04df0d20b Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 11 Oct 2010 14:35:57 -0700 Subject: [PATCH 2/5] Making the translation keys cas insensitive, and making generic keys explicit --HG-- branch : dev --- .../Services/DefaultLocalizedStringManager.cs | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/Orchard/Localization/Services/DefaultLocalizedStringManager.cs b/src/Orchard/Localization/Services/DefaultLocalizedStringManager.cs index 212acbd4c..e4f7a95f5 100644 --- a/src/Orchard/Localization/Services/DefaultLocalizedStringManager.cs +++ b/src/Orchard/Localization/Services/DefaultLocalizedStringManager.cs @@ -47,12 +47,13 @@ namespace Orchard.Localization.Services { foreach (var culture in cultures) { if (String.Equals(cultureName, culture.CultureName, StringComparison.OrdinalIgnoreCase)) { - string scopedKey = scope + "|" + text; - string genericKey = "|" + text; + string scopedKey = (scope + "|" + text).ToLowerInvariant(); if (culture.Translations.ContainsKey(scopedKey)) { return culture.Translations[scopedKey]; } - if (culture.Translations.ContainsKey(genericKey)) { + + string genericKey = ("|" + text).ToLowerInvariant(); + if ( culture.Translations.ContainsKey(genericKey) ) { return culture.Translations[genericKey]; } @@ -64,8 +65,8 @@ namespace Orchard.Localization.Services { } private static string GetParentTranslation(string scope, string text, string cultureName, IEnumerable cultures) { - string scopedKey = scope + "|" + text; - string genericKey = "|" + text; + string scopedKey = (scope + "|" + text).ToLowerInvariant(); + string genericKey = ("|" + text).ToLowerInvariant(); try { CultureInfo cultureInfo = CultureInfo.GetCultureInfo(cultureName); CultureInfo parentCultureInfo = cultureInfo.Parent; @@ -183,24 +184,13 @@ namespace Orchard.Localization.Services { 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); - } - else { - if (merge) { - translations[scopedKey] = translation; - } - } - } - string genericKey = "|" + id; - if (!translations.ContainsKey(genericKey)) { - translations.Add(genericKey, translation); + string scopedKey = (scope + "|" + id).ToLowerInvariant(); + if (!translations.ContainsKey(scopedKey)) { + translations.Add(scopedKey, translation); } else { if (merge) { - translations[genericKey] = translation; + translations[scopedKey] = translation; } } } From c7bfc8c1302f2c0f69c858aeea2b4322f1fc5295 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 11 Oct 2010 15:24:11 -0700 Subject: [PATCH 3/5] Localizing Themes and Modules - Added sample localizations for French --HG-- branch : dev --- .../Orchard.Blogs/Orchard.Blogs.csproj | 3 ++ .../Orchard.Modules/Orchard.Modules.csproj | 4 ++ .../Orchard.Modules/Services/ModuleService.cs | 49 ++++++++++++++----- .../Orchard.Themes/Orchard.Themes.csproj | 4 ++ .../Orchard.Themes/Services/ThemeService.cs | 31 +++++++++--- src/Orchard.Web/Orchard.Web.csproj | 1 + .../Localization/LocalizationUtilities.cs | 9 ++-- 7 files changed, 79 insertions(+), 22 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index 6babf2c8f..d4dce537d 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -181,6 +181,9 @@ + + + - -
-
+ +
+
- + - - + + @@ -31,7 +31,7 @@ - +