I need to add localization to my ASP.NET Core Application.
I don't know what is the best way to archieve this goal... I want to have external files which contains the different translations so I can modify them without have to compile my application again.
What I saw on the Internet, there is two ways to add localization in a .Net Core app : - With .resx files but you can't modify them as you want - With .po files which seems to be what I need.
However, I don't know if .po files are really a good solution... There is a nugget Package "OrchardCore.Localization.Core" which configure the PO file support but it is a beta version without a lot of changes and for what I read, it doesn't seems to work very well with DataAnnotations.
What do you think ? What can be the best solution for my problem ?
Indeed, resx files are compiled into binary files (satellite assemblies) during the build process so you cannot modify them (simply, at least) without recompiling them.
On the contrary, PO files are plain text files which can be easily edited at any time.
This is one of the good reasons I've been using PO instead of the built-in, resx based localization in my projects for quite a while now. I took the idea from the Orchard CMS project (the "classic" one) and it works very well for me. I think the fact that the authors have stuck to PO in the .NET Core re-implementation of Orchard is a good indicator that PO is a viable option for localization.
To get PO localization going in ASP.NET Core, you will need:
A PO file parser. Orchard Core must include something like this but I don't know how mature is. I needed this functionality back in the day when I switched to .NET Core and implemented it on .NET Standard. Later I released it under MIT license.
A custom implementation of IStringLocalizer. This is not too difficult to do. You find an example of this e.g. here.
However, to make the workflow of localization as painless as possible, it's recommended to use a good PO editor and to implement localization in such a way which enables automated extraction of translatable texts. You can find more about this topic here.
As for data annotations: I don't know the exact details how localization is implemented in Orchard Core but if you go down the IStringLocalizer path, you should have neither less nor more problems with localization of data annotations as if you used the default resx implementation. (There are some known issues regarding data annotation localization like this one but nothing so serious which would be too difficult to tackle.)