Skip to content

folkelib/Folke.Localization.Json

Repository files navigation

Folke.Localization.Json

This is an implementation of IStringLocalizer from ASP.NET 5 that uses Json files.

Initialize it in you Startup ConfigureServices method:

services.AddJsonLocalization(options =>
{
	options.ResourceFilesDirectory = "res"; // The directory that contains the resources
	options.DefaultBaseName = "text"; // The default sub-directory name
});

For a Sample.Type type and the culture ab-CD, the service will look for a JSON file in the following order:

  • {ResourceFilesDirectory}/{Sample.Type}/{ab-CD}.json
  • {ResourceFilesDirectory}/{Sample.Type}/default.json
  • {ResourceFilesDirectory}/{DefaultBaseName}/{ab-CD}.json
  • {ResourceFilesDirectory}/{DefaultBaseName}/default.json

The JSON file may be a tree of string values. The keys are formed using the : separator. For example for the file:

{
	"first": {
		"second": "value"
	},
	"third": "other value"
}

The key first:second would return value and the key third would return other value. Any other key would result in an error.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published