--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-10-11 18:05:36 -07:00
8 changed files with 105 additions and 45 deletions

View File

@@ -181,6 +181,9 @@
<ItemGroup>
<Content Include="Views\Parts\Tags.ShowTags.Detail.BlogPost.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="App_Data\Localization\fr-FR\orchard.module.po" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -39,6 +39,10 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=2.2.4.900, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\autofac\Autofac.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.ComponentModel.DataAnnotations">

View File

@@ -15,12 +15,17 @@ namespace Orchard.Modules.Services {
private const string ModuleExtensionType = "module";
private readonly IExtensionManager _extensionManager;
private readonly IShellDescriptorManager _shellDescriptorManager;
private readonly IWorkContextAccessor _workContextAccessor;
public ModuleService(IOrchardServices orchardServices, IExtensionManager extensionManager,
IShellDescriptorManager shellDescriptorManager) {
public ModuleService(
IOrchardServices orchardServices,
IExtensionManager extensionManager,
IShellDescriptorManager shellDescriptorManager,
IWorkContextAccessor workContextAccessor) {
Services = orchardServices;
_extensionManager = extensionManager;
_shellDescriptorManager = shellDescriptorManager;
_workContextAccessor = workContextAccessor;
T = NullLocalizer.Instance;
}
@@ -187,17 +192,37 @@ namespace Orchard.Modules.Services {
: featuresInQuestion.First()));
}
private static IModule AssembleModuleFromDescriptor(ExtensionDescriptor extensionDescriptor) {
private static string TryLocalize(string key, string original, Localizer localizer) {
var localized = localizer(key).Text;
if(key == localized) {
// no specific localization available
return original;
}
return localized;
}
private IModule AssembleModuleFromDescriptor(ExtensionDescriptor extensionDescriptor) {
var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(extensionDescriptor.Location, "/", extensionDescriptor.Name, "/Module.txt"));
return new Module {
ModuleName = extensionDescriptor.Name,
DisplayName = extensionDescriptor.DisplayName,
Description = extensionDescriptor.Description,
Version = extensionDescriptor.Version,
Author = extensionDescriptor.Author,
HomePage = extensionDescriptor.WebSite,
Tags = extensionDescriptor.Tags,
Features = extensionDescriptor.Features
};
ModuleName = extensionDescriptor.Name,
DisplayName = TryLocalize("Name", extensionDescriptor.DisplayName, localizer),
Description = TryLocalize("Description", extensionDescriptor.Description, localizer),
Version = extensionDescriptor.Version,
Author = TryLocalize("Author", extensionDescriptor.Author, localizer),
HomePage = TryLocalize("Website", extensionDescriptor.WebSite, localizer),
Tags = TryLocalize("Tags", extensionDescriptor.Tags, localizer),
Features = extensionDescriptor.Features.Select(f => new FeatureDescriptor {
Category = TryLocalize(f.Name + " Category", f.Category, localizer),
Dependencies = f.Dependencies,
Description = TryLocalize(f.Description + " Description", f.Description, localizer),
Extension = f.Extension,
Name = f.Name
})
};
}
private static IModuleFeature AssembleModuleFromDescriptor(Feature feature, bool isEnabled) {

View File

@@ -39,6 +39,10 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=2.2.4.900, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\autofac\Autofac.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />

View File

@@ -19,14 +19,17 @@ namespace Orchard.Themes.Services {
private readonly IExtensionManager _extensionManager;
private readonly IEnumerable<IThemeSelector> _themeSelectors;
private readonly IModuleService _moduleService;
private IWorkContextAccessor _workContextAccessor;
public ThemeService(
IExtensionManager extensionManager,
IEnumerable<IThemeSelector> themeSelectors,
IModuleService moduleService) {
IModuleService moduleService,
IWorkContextAccessor workContextAccessor) {
_extensionManager = extensionManager;
_themeSelectors = themeSelectors;
_moduleService = moduleService;
_workContextAccessor = workContextAccessor;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
@@ -174,15 +177,29 @@ namespace Orchard.Themes.Services {
_extensionManager.UninstallExtension("Theme", themeName);
}
private static ITheme CreateTheme(ExtensionDescriptor descriptor) {
private static string TryLocalize(string key, string original, Localizer localizer) {
var localized = localizer(key).Text;
if ( key == localized ) {
// no specific localization available
return original;
}
return localized;
}
private ITheme CreateTheme(ExtensionDescriptor descriptor) {
var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(descriptor.Location, "/", descriptor.Name, "/Theme.txt"));
return new Theme {
Author = descriptor.Author ?? "",
Description = descriptor.Description ?? "",
DisplayName = descriptor.DisplayName ?? "",
HomePage = descriptor.WebSite ?? "",
Author = TryLocalize("Author", descriptor.Author, localizer) ?? "",
Description = TryLocalize("Description", descriptor.Description, localizer) ?? "",
DisplayName = TryLocalize("Name", descriptor.DisplayName, localizer) ?? "",
HomePage = TryLocalize("Website", descriptor.WebSite, localizer) ?? "",
ThemeName = descriptor.Name,
Version = descriptor.Version ?? "",
Tags = descriptor.Tags ?? "",
Tags = TryLocalize("Tags", descriptor.Tags, localizer) ?? "",
Zones = descriptor.Zones ?? "",
BaseTheme = descriptor.BaseTheme ?? "",
};

View File

@@ -139,6 +139,7 @@
<Content Include="Themes\TheThemeMachine\Styles\site.css" />
<Content Include="Themes\TheThemeMachine\Theme.png" />
<Content Include="Themes\TheThemeMachine\Theme.txt" />
<None Include="Themes\Classic\App_Data\Localization\fr-FR\orchard.theme.po" />
<None Include="Themes\TheThemeMachine\Views\Layout-homePage.cshtml" />
<None Include="Themes\TheThemeMachine\Views\Recent.cshtml">
<SubType>Designer</SubType>

View File

@@ -1,12 +1,15 @@
using System.Web.Mvc;
using Autofac;
using Orchard.Mvc;
namespace Orchard.Localization {
public class LocalizationUtilities {
public static Localizer Resolve(WorkContext workContext, string scope) {
return workContext == null ? NullLocalizer.Instance : Resolve(workContext.Resolve<ILifetimeScope>(), scope);
}
public static Localizer Resolve(ControllerContext controllerContext, string scope) {
var context = controllerContext.GetWorkContext();
return context == null ? NullLocalizer.Instance : Resolve(context.Resolve<ILifetimeScope>(), scope);
var workContext = controllerContext.GetWorkContext();
return Resolve(workContext, scope);
}
public static Localizer Resolve(IComponentContext context, string scope) {

View File

@@ -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";
@@ -46,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];
}
@@ -63,8 +65,8 @@ namespace Orchard.Localization.Services {
}
private static string GetParentTranslation(string scope, string text, string cultureName, IEnumerable<CultureDictionary> 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;
@@ -109,6 +111,7 @@ namespace Orchard.Localization.Services {
// In reverse priority order:
// "~/Core/App_Data/Localization/<culture_name>/orchard.core.po";
// "~/Modules/<module_name>/App_Data/Localization/<culture_name>/orchard.module.po";
// "~/Themes/<theme_name>/App_Data/Localization/<culture_name>/orchard.theme.po";
// "~/App_Data/Localization/<culture_name>/orchard.root.po";
// "~/App_Data/Sites/<tenant_name>/Localization/<culture_name>/orchard.po";
// The dictionary entries from po files that live in higher priority locations will
@@ -124,17 +127,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) {
@@ -170,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;
}
}
}