6.8.0, Angular, .NET Framework
Is it possible to extend default localization resources like described here?: Extending Localization Sources
I'm asking because I get the following error when I try to do so:
FATAL 2019-03-29 13:39:47,595 [1 ] Abp.AbpBootstrapper - Abp.AbpInitializationException: ProjectName source contains more than one dictionary for the culture: en
bei Abp.Localization.Dictionaries.Xml.XmlEmbeddedFileLocalizationDictionaryProvider.Initialize(String sourceName)
bei Abp.Localization.MultiTenantLocalizationSource.Initialize(ILocalizationConfiguration configuration, IIocResolver iocResolver)
bei Abp.Localization.LocalizationManager.InitializeSources()
bei Abp.AbpKernelModule.PostInitialize()
bei System.Collections.Generic.List`1.ForEach(Action`1 action)
bei Abp.AbpBootstrapper.Initialize()
Abp.AbpInitializationException: ProjectName source contains more than one dictionary for the culture: en
bei Abp.Localization.Dictionaries.Xml.XmlEmbeddedFileLocalizationDictionaryProvider.Initialize(String sourceName)
bei Abp.Localization.MultiTenantLocalizationSource.Initialize(ILocalizationConfiguration configuration, IIocResolver iocResolver)
bei Abp.Localization.LocalizationManager.InitializeSources()
bei Abp.AbpKernelModule.PostInitialize()
bei System.Collections.Generic.List`1.ForEach(Action`1 action)
bei Abp.AbpBootstrapper.Initialize()
FATAL 2019-03-29 13:39:47,700 [1 ] soft.AspNetCore.Hosting.Internal.WebHost - Application startup exception
Abp.AbpInitializationException: ProjectName source contains more than one dictionary for the culture: en
bei Abp.Localization.Dictionaries.Xml.XmlEmbeddedFileLocalizationDictionaryProvider.Initialize(String sourceName)
bei Abp.Localization.MultiTenantLocalizationSource.Initialize(ILocalizationConfiguration configuration, IIocResolver iocResolver)
bei Abp.Localization.LocalizationManager.InitializeSources()
bei Abp.AbpKernelModule.PostInitialize()
bei System.Collections.Generic.List`1.ForEach(Action`1 action)
bei Abp.AbpBootstrapper.Initialize()
bei Abp.AspNetCore.AbpApplicationBuilderExtensions.InitializeAbp(IApplicationBuilder app)
bei Abp.AspNetCore.AbpApplicationBuilderExtensions.UseAbp(IApplicationBuilder app, Action`1 optionsAction)
bei CompanyName.ProjectName.Web.Startup.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
My folder structure for localization resources looks like this:
- Localization
- ProjectName
- ProjectName.xml
- ProjectName-xx.xml
- ...
- ProjectNameExtended.xml
- ProjectName.xml
- ProjectName-xx.xml
- ...
- ProjectName
ProjectNameLocalizationConfigurer.cs looks like this:
public static void Configure(ILocalizationConfiguration localizationConfiguration)
{
localizationConfiguration.Sources.Add(
new DictionaryBasedLocalizationSource(
ProjectNameConsts.LocalizationSourceName,
new XmlEmbeddedFileLocalizationDictionaryProvider(
typeof(ProjectNameLocalizationConfigurer).GetAssembly(),
"CompanyName.ProjectName.Localization.ProjectName"
)
)
);
localizationConfiguration.Sources.Extensions.Add(
new LocalizationSourceExtensionInfo(
"(ProjectName",
new XmlEmbeddedFileLocalizationDictionaryProvider(
typeof(ProjectNameLocalizationConfigurer).GetAssembly(),
"CompanyName.ProjectName.Localization.ProjectNameExtended"
)
)
);
}
Please, advise!
EDIT: Removed project name from code-block
27 Answer(s)
-
1
yes, localization extension only works for localization files with the same name.
-
0
This was an extremely confusing post to address the issue of extending a localization source, which allows overriding existing entries and adding new ones. I wanted to organize things so that what I add for my application is separate from the AspNetZero supplied language files. To summarize the solution, you need to do the following assuming a project "YourProject" is the project that is provided from AspNetZero:
- In folder YourProject.Core/Localization, you find a YourProject folder with language files prefixed with "YourProject" (e.g. YourProject.xml, YourProject-de.xml, etc.
- You need to add a folder under YourProject.Core/Localization with a different name like "ExtendYourProject".
- In the new Folder, for any languages you want to extend, add a file with the SAME name as the language file you are extending (e.g., YourProject-de.xml). The file will contain any entries you want to override and any new entries.
- In the language configurer in YourProject.Core/Localization file YourProjectLocalizationConfigurer add the code:
localizationConfiguration.Sources.Extensions.Add( new LocalizationSourceExtensionInfo("YourProject", new XmlEmbeddedFileLocalizationDictionaryProvider( typeof(YourProjectLocalizationConfigurer).GetAssembly(), "YourProject.Localization.ExtendYourProject" ) ) );
Rebuild, and you should find that the extensions are now used. You do need to make sure that the "build action" for any files you add are showing "Embedded Resource". Any XML files that I added seem to be given that automatically in visual studio.
Hope that helps makes sense of a rather long involved post for something relatively simple in the end.