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)
-
0
Abp.AbpInitializationException: ProjectName source contains more than one dictionary for the culture: en
Check the culture specified in the files.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Aaron, really helpful comment ... I would expect a more elaborate answer from support guys
@alexanderpilhar This should work (I had a hard time finding a solution some tome ago, documentation is not really clear on this):
Localization ProjectName ProjectName.xml ProjectName-xx.xml ... Extended ProjectName.xml ProjectName-xx.xml ...
public static void Configure(ILocalizationConfiguration localizationConfiguration) { localizationConfiguration.Sources.Add( new DictionaryBasedLocalizationSource( ProjectNameConsts.LocalizationSourceName, new XmlEmbeddedFileLocalizationDictionaryProvider( typeof(PoinowLocalizationConfigurer).GetAssembly(), "CompanyName.ProjectName.Localization.ProjectName" ) ) ); localizationConfiguration.Sources.Extensions.Add( new LocalizationSourceExtensionInfo( ProjectNameConsts.LocalizationSourceName, new XmlEmbeddedFileLocalizationDictionaryProvider( typeof(PoinowLocalizationConfigurer).GetAssembly(), "CompanyName.ProjectName.Localization.Extended" ) ) ); }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@aaron as far as I understand linked documentation, the culture specified in the files should be okay - I'm trying to extend
CompanyName.ProjectName.Localization.ProjectName.ProjectName.xml(which isculture="en") withCompanyName.ProjectName.Localization.ProjectNameExtended.ProjectName.xml(which isculture="en"as well).@geertveenstra did you mean to move all default localization files from
CompanyName.ProjectName.Localization.ProjectNametoCompanyName.ProjectName.Localization? And therootNamespace: "CompanyName.ProjectName.Localization.ProjectName"forXmlEmbeddedFileLocalizationDictionaryProviderstill works?Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Check the culture specified in the files in the ProjectNameExtended folder.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
1
@alexanderpilhar,
Sorry, the indentation was not good.
This would be the structure of the directories:
- Localization
- ProjectName (this is your projectname where the original aspnetzero localization files are)
- ProjectName.xml (for english (en))
- ProjectName-de.xml (for german (de))
- ProjectName-nl.xml (for dutch (nl))
- ...
- Extended (this is your new extension directory where your added/changed localization keys are)
- ProjectName.xml (for english (en))
- ProjectName-de.xml (for german (de))
- ProjectName-nl.xml (for dutch (nl))
- ...
- ProjectName (this is your projectname where the original aspnetzero localization files are)
The problem is the extension directory can apparently not have the name starting with ProjectName (e.g. ProjectNameExtended), somehow that will not work) so just give it another name.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) - Localization
-
0
-
0
@aaron here are the cultures specified in ProjectNameExtended folder:
ProjectName.xml: culture="en"ProjectName-de.xml: culture="de"
@geertveenstra I see. I did as you described but now my resource extension files cannot be found at all ... Note: I did make sure to set build-process to embedded resource for the files. I also checked namespace for errors.
@maliming thanks for your comment! I think I'm falling in love with the json resource files :D They seem to be much more readable!
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Maybe I'm all wrong about the rootNamespace?
Documentation says (Registering XML Localization Sources):
XmlEmbeddedFileLocalizationDictionaryProvider gets an assembly containing XML files (GetExecutingAssembly simply refers to current assembly) and a namespace of XML files (namespace is the calculated assembly name + folder hierarchy of XML files).
And this is XmlEmbeddedFileLocalizationDictionaryProvider.cs
@geertveenstra this line explains why extension directory name cannot start with ProjectName.
So, it seems my original problem was caused by the resource extension folder name starting with ProjectName. Now that I have renamed this folder from ProjectNameExtended to Extended, resource extension files don't seem to have any effect at all.
This is what
Logs.txtsays:WARN 2019-04-02 10:30:54,713 [4 ] naries.DictionaryBasedLocalizationSource - Can not find 'Text.Name' in localization source 'ProjectName'! ... (and some more of the same)Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@alexanderpilhar If I use a template project(https://github.com/aspnetboilerplate/module-zero-core-template) to show you the extension's built-in localization, what do you think?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@maliming that would be great : )
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
https://github.com/maliming/abplocalization/blob/master/src/QA.Web.Mvc/Controllers/HomeController.cs#L17
https://github.com/maliming/abplocalization/blob/master/src/QA.Core/Localization/SourceFiles/Abp/Abp.xml#L4
https://github.com/maliming/abplocalization/blob/master/src/QA.Core/Localization/QALocalizationConfigurer.cs#L23
Access this url: http://localhost:62114/home/test
{ "result": null, "targetUrl": null, "success": false, "error": { "code": 0, "message": "Hello You Need Login!", "details": null, "validationErrors": null }, "unAuthorizedRequest": true, "__abp": true }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@maliming thank you for the provided example!
I see you are extending Abp localization resource files. In my case, I'm trying to extend QA localization resource files - which I cannot make work.
Basically, what I'm trying to do is to split the localization resource files that come with ASPNETZERO into multiple files depending on context. But that's just a nice-to-have and not a must-have. So, for now I will give up on this and continue putting all my text-elements in the single resource file.
Nevertheless, thanks for your time and help @all!
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
1
Basically, what I'm trying to do is to split the localization resource files that come with ASPNETZERO into multiple files depending on context.
That is exactly what I did ... Working fine here (but like I mentioned, it only works when your Extension folder names do not start with your Project folder name). Don't know how to explain it further.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@geertveenstra the answer you provided looks really promising to me and I really think it is correct. I don't know why localization won't be applied when I implement it your way (there might be something I'm still missing) - I might give it a try another time or I might try to implement it in a fresh project. Anyway, as soon as I get it to work with the solution you provided, I will mark your answer as the correct one!
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
We are using the .net Core + Angular version 6.9.1 and I wanted to do the same. I wanted to have several xml files so I could organize the translations more clearly.
I have the same problem. No matter what I do, the additional files are ignored. It only takes the translation from the main file.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@alexanderpilhar did you find the bug? None of the combinations work for me.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@FlexSolution unfortunately no, not yet. I will try again using a clean project as soon as I find the time to do so.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I downloaded a completely clean project today. Combination .Net-Core and Angular, version 6.9.1
It just doesn't work.
Maybe someone from support can just download our project and try to add more language files in another folder?
@alexanderpilhar Maybe you will open this request here again so that I don't create a new one unnecessarily although it is the same topic?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Reopening as requested by @FlexSolution.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)
-
0
I sent you everything. Maybe I'm missing something. But there are also no error messages.
I'm curious to see where the error is.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I sent the mail a week ago and haven't received any feedback yet. Can you confirm if the mail arrived at all?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @FlexSolution
Sorry, the email was in spam foldr, I just saw it. We are checking it.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
1
Hi again,
I tested your project and changing the xml file name from 'abc.xml' to 'FlexSped.xml' and using beloc code block in FlexSpedLocalizationConfigurer.cs worked. Could you also try that ?
localizationConfiguration.Sources.Extensions.Add( new LocalizationSourceExtensionInfo( "FlexSped", new XmlEmbeddedFileLocalizationDictionaryProvider( typeof(FlexSpedLocalizationConfigurer).GetAssembly(), "FlexSped.Localization.Second" ) ) );Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
So it is not possible to name the XML file the way you want, just the folder?
I also tried this:
localizationConfiguration.Sources.Add( new DictionaryBasedLocalizationSource("Group2", new XmlEmbeddedFileLocalizationDictionaryProvider( typeof(FlexSpedLocalizationConfigurer).GetAssembly(), "FlexSped.Localization.Group2" ) ) );to insert a new source instead of extending the existing one.The only way it works is to extend the existing ones and give each XML file the same name?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)
