This project allows you to use JSON files for .NET Core Localization instead of resx files.
- Works with multiple projects/assemblies (i.e. the resources can stay in the project where they belong).
- Automatic fallback to parent culture (e.g. if a resource is not found in 'de-CH', it is also searched for in 'de' resources).
The following are the required steps to activate the embedded JSON localization. For all other information consider the official Globalization and localization in ASP.NET Core docs.
- Add the package reference:
- In Startup.cs:
public void ConfigureServices(...)
{
...
services.AddJsonLocalization();
...
}
- Embed the json in the corresponding project files (csproj). For example:
<ItemGroup>
<EmbeddedResource Include="**/*.de-CH.json" />
</ItemGroup>
You can find a fully working sample in the source code. Note that the cookie consent has been localized (to show an instance of view localization) and the header messages of the About and Contact screens (to have an example of localization happening in a controller inlcuding fallback to parent culture).