Using ASPNETZERO 11.0 .NET Core/Mvc
I need to integrate .resx files for localization in addition to the built-in xml localization files. My MVC app has over 100 entities with CRUD pages so managing multiple languages with single XML files is not practical. We have added a Blazor Mobile app to the solution and in that have implemented the ResXManager Visual Studio etension which automatically generates new resx files when a new language is added. I want to bring that approach over to the Mvc version. The .resx files will be stored in a /Resources folder using the path and filename of the View.
I have tried adding resx statements to Startup.cs. It builds but only displays the information inside the @Localizer["Term1"] and does not find the matching resx value.
Has anyone gotten .resx files to work? If so, I would appreciate seeing how you set it up in Startup.cs
Thanks
14 Answer(s)
-
0
Hi @outdoored
Could you take a look at https://aspnetboilerplate.com/Pages/Documents/Localization#resource-files and see if it helps you.
-
0
Can we use resx files for our custom Entitues and screens following the Microsoft approach of using 1 resx file per screen? Is there a way of bypassing the ASPBoilerplate approach for our own screens? With 100 entities and 4+ CRUD screens per Entity, using the built-in approach where there is only one resx file for thousands of lines of translations is not possibel for us.
-
0
To clarify my question. I understand that I need to keep the ABP XML localization and XML files for handling languages. I want to have a second localization service that will allow me to include the default Microsoft approach using individual resx files for each Razor page in NetCore 11 & Jquery.
-
0
Hi @outdoored
Sure, you can use RESX files for your newly created pages if you are creating them manually. AspNet Boilerplate supports adding multiple localization sources. You can add a new localization source (see https://aspnetboilerplate.com/Pages/Documents/Localization#resource-files) with a diffrent name and use it in any page you want. If you want to create a separete resx file for each page, you can name the localization resource with the page name.
-
0
I tried to set-up translations in the project using the official documentation here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-6.0
I created a separate branch for this in our existing 11 Net Core Jquery. In this branch I added the two necessary nuget packages (Localization and Localization.Abstractions), I included the resx files in a folder structure and configured localization in the startup file.
Startup.cs
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, opts => { opts.ResourcesPath = "Resources"; }) .AddDataAnnotationsLocalization() services.AddLocalization(options => options.ResourcesPath = "Resources");
But even with all these steps the resx translations are ignored. After digging in the code a bit I found out that aspnet zero has its own way of handling translations and is overriding the default dot net way.
According to the forum post and the linked article we should be able to register the resx files in the OE_TenantLocalizationConfigurer
But the problems I’m facing:
- How can we use the resx folder structure with aspnet zero and have different resx files for each view and viewmodel, without needing one resx file for all translations?
- How can we lazy load these resx files without having to register them all at once ?
I can’t seem to find a way on how to do this and your documentation isn’t helping me any further. Could you provide a working example?
-
0
Hi @outdoored
It is not possible to lazy load the resources. I'm not sure if ASP.NET Core even supports it or not. You can programatically find the resx files under a specific folder and its subfolders and register them as shown in the picture you have shared.
-
0
Thanks. I am still trying to get this to work with a single resx file. I have the file in
MYAPP.Web.Mvc/Resources/IncidentsLanguage.resx
I have tried adding the code below to MYAPP.Web.Mvc/Startup/MYAPPWebMvcModule.cs but it will not recognize the existence of the resx file. When I type .Resources I get Intellisense prompts for the other files in that folder (IWebResourcesManager, WebResourcesManager, ScriptManager) but it does not find the .resx file.
using Abp.Localization.Sources.Resource;
Configuration.Localization.Sources.Add( new ResourceFileLocalizationSource( "MySource", Resources.IncidentsLanguage.ResourceManager ));
I see there is also a MYAPPLocalizationConfigurer.cs in MYAPP.Core does the resx also need to be defined here?
public static void Configure(ILocalizationConfiguration localizationConfiguration) { localizationConfiguration.Sources.Add( new DictionaryBasedLocalizationSource( OE_TenantConsts.LocalizationSourceName, new XmlEmbeddedFileLocalizationDictionaryProvider( typeof(OE_TenantLocalizationConfigurer).GetAssembly(), "OE_Tenant.Localization.OE_Tenant" )
-
0
Hi @outdoored
Is it possible to share your project with [email protected] ? We can take a look at this for you.
-
0
I will package up a demo project and send a link
-
0
Thanks @outdoored
-
0
I sent the link to our demo project and want to confirm that you received it
-
0
Hi @outdoored
Our team couldn't build your solution because of the missing files.
But, we have a suggestion for you. Could you try getting the localized key as explained here https://aspnetboilerplate.com/Pages/Documents/Localization?searchKey=resx#getting-a-localized-text instead of using L("Title") ?
If it doesn't work, could you share the files below via email;
Line GetEventsInput DocumentTemplate IFileDocIoGenerator FileDocIoGeneratorEventsJobArgs DocumentTemplateField DynamicPropertyKey Any changes made on LogisavDbContext
Thanks,
-
0
I was able to run the demo solution locally. I will send you a link to a new zip file. It is running ASP.NET Core Mvc Jquery 11 with a database called OE_TenantDb. In the MVC Project there is a View \TranslationDemo\Index.cshtml and another in the \Areas\Admin\TranslationDemo\Index.cshtml
-
0
Hi @outdoored
I have requested access to download project from Google Drive. Could you grant access for me ?
Thanks,