2
votes

I have dealt with localization of many .net Core 2.2 applications.

I am working now on a .net Core 3.1 localized application

In the Startup.cs ConfigureServices I have

services.AddLocalization(o =>
        {
            // We will put our translations in a folder called Resources
            o.ResourcesPath = "Resources";
        });

        services.AddControllersWithViews()
            .AddViewLocalization(LanguageViewLocationExpanderFormat.SubFolder)
            .AddDataAnnotationsLocalization()
            .AddNewtonsoftJson(); 

In the Configure method I define my cultures and such and include

app.UseRequestLocalization(localizationOptions);

I have a folder structure for my resources that looks like this: enter image description here

My views are all localizing perfect. However none of the models/Data annotations or controllers will localize even though they are named correctly and placed in the models or controllers folder.

In prior 2.2 using the folder structure worked flawlessly for me. Have I missed something new under 3.1 that should be telling it to look in the folder differently? Should the folder not be named Models but something else?

I have looked in all the docs, searched online, but am coming up short.

Updated See Answer below

3

3 Answers

2
votes

Working Answer for now:

It appears that I can get the controllers and the models to localize by moving them out of the subfolders and changing the name of each resx to include the NameSpace.Models.Modelname for models and NameSpace.Controllers.Controllername for controllers. This is the only way I can currently get them to work.

So apparently only views will use the folder/subfolder methodology? Unless I totally missed this I think this is either a huge issue or a breaking change that I don't see documented clearly anywhere.

I have not had confirmation from MS that this is a breaking change, but it sure appears to be to me at this point. If you are moving from earlier .net core localization this will come as a surprise or it did to me anyway. Hope this helps someone else.

0
votes

I have used this github package for localization. Works very well and is reasonably easy to implement. I know this doesn't directly answer your question, but it is a potential workaround.

https://github.com/LazZiya/ExpressLocalization/wiki

-1
votes

Create the simplest possible app that localizes models/Data annotations and works with 2.2 and fails in 3.1 That might help find the problem. If it doesn't, open an issue on the loc doc and provide a link to the repo.

Go to the bottom of the loc page and select this page

Do you plan migrating from AddNewtonsoftJson? See Newtonsoft.Json (Json.NET) support