The code implements a localization in ASP.NET Core 3+ by non-compiled RESX file.
-
Download a content of folder src and include the files into your project (change namespace ...)
-
Initialization in
Startup.cs
in methodeConfigureServices
services.AddOpenResxLocalization(options => options.ResourcesPath = "Resources");
-
Create a folder with name 'Resources' in base project folder and in it create folders by typical localization steps (You have to use a path naming - Globalization and localization in ASP.NET Core)
For example:
-
Set properties of resx file
-
It is all.
- It works with all type of localizations: in Controllers, in Views and in DataAnnotations.
- It is possible to use it in desktop applications, web applications (ASP.NET) and libraries.
- I don't have an expirience with hosting the code on Linux.
I have look for on the Internet libraries, nugets and articles on blogs where somebody solves this issue but I can not find anything. I have to create my own solution and I hope it helps you. If you have a tip for improvment, you will write it. I will pleasere.
- OpenResxResourceManager uses XDocument for finding a localized value, because I have found an article where somebody write. The XDocument is faster than XmlDocument. There is both impelementation (XDocument is used and XmlDocument is commented)
- OpenResxResourceManager has only one constructor but other constructors are commented.