Localization additions and extensions for .NET.
Path-based localization implemented with JSON- and XML-localization.
Built on ASP.NET Core localization:
The functional idea behind it:
To get the FileResourcesDirectoryPath to be null it have to be absent from the configuration-file". This want work:
{
"Localization": {
"FileResourcesDirectoryPath": null
}
}
AppSettings.json example:
{
"Localization": {
"AlphabeticalSorting": true,
"EmbeddedResourceAssemblies": [
"Animals",
"Colors",
"Numbers",
"Prioritized-words",
"Root-namespaced-resources",
"Words"
],
"FileResourcesDirectoryPath": "Resources",
"IncludeParentCultures": false,
"ThrowErrors": false
}
}
Example: Web-application startup
...
builder.Services.AddPathBasedLocalization(builder.Configuration);
...
{
"LocalizationDependencyInjection": {
"StaticCache": true
}
}
...
builder.Services.AddPathBasedLocalization(localizationOptions =>
{
localizationOptions.AlphabeticalSorting = true;
localizationOptions.EmbeddedResourceAssemblies.Add("Assembly-name"); // Can be an assembly-name, assembly-name-pattern (MyAssembly*) or an assembly-fullname.
localizationOptions.FileResourcesDirectoryPath = "Resources";
});
...
...
builder.Services.AddPathBasedLocalization(localizationOptions =>
{
localizationOptions.AlphabeticalSorting = true;
localizationOptions.EmbeddedResourceAssemblies.Add("Assembly-name"); // Can be an assembly-name, assembly-name-pattern (MyAssembly*) or an assembly-fullname.
localizationOptions.FileResourcesDirectoryPath = "Resources";
}, true);
...
...
builder.Services.AddPathBasedLocalization();
...
...
builder.Services.AddPathBasedLocalization(true);
...
IStringLocalizer:
IStringLocalizer<T>, example where T is Company.WebApplication.Controllers.HomeController:
A localization-entry can be a lookup to another entry:
{
"Cultures": [
{
"Culture": {
"Name": "en",
"Nodes": [
{
"Node": {
"Name": "Common",
"Entries": {
"Yes": {
"Value": "Yes"
}
}
}
},
{
"Node": {
"Name": "Company.WebApplication.Controllers.HomeController",
"Entries": {
"Yes": {
"Lookup": "Common.Yes"
}
}
}
}
]
}
}
]
}
<cultures>
<culture name="en">
<common>
<yes>Yes</yes>
</common>
<company>
<webApplication>
<controllers>
<homeController>
<yes lookup="common.yes" />
</homeController>
</controllers>
</webApplication>
</company>
</culture>
</cultures>
Drop the "StrongName.snk" file in the repository-root. The file should not be included in source control.