Localization in ASP .NET Core 2.0 - Best practice

Viewed 3311

I'm using ASP.NET Core 2.0 and I want to be able to use string localization in custom classes, not only in Controllers (working with bot framework - dialog localization ). What is best practice for localization and globalization in ASP .Net Core 2.0? Do I have to use IStringLocalizer in every controller? Is there any global way of doing it? Does anybody know why there is recommendation in official documentation not to use default .resx file but to use name.localization.resx wich doesn't automatically create file in Visual studio like in .NET when using default .resx?

2 Answers

Regarding localization support: , I use localization via route but the default provider by itself doesn't support passing two letters (en instead of en-UK for example) and it's hard to support optional language passing if the key is in the beginning or middle of the url (like ~/{lang}/api/...).
I use this package to ease the things for me:
https://www.nuget.org/packages/AspNetCore.RequestLocalizationPipeline

A resource is a link between keys and values. Every key is linked to some html-document.

Here's the question you'll need to ask yourself before starting to build up your resource files.

Will you have key (Dom-elements) in different views with the same key-name? And do you want them to have different or equal values? (and will you be working like this consistently).

If the answer is 'different' => resolve IStringLocalizer in every controller, else, make a shared resource as doucmented in

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.1#implement-a-strategy-to-select-the-languageculture-for-each-request

Related