Skip to content

A localization implementation using json files and DistributedCache for asp.net core

License

Notifications You must be signed in to change notification settings

aodpi/Anvyl.JsonLocalizer

Repository files navigation

JsonLocalizer for ASP.NET Core 2.0 onward

Appveyor Travis
Build status Build Status

This package is an Implementation of IStringLocalizer for asp.net core. It uses json files to store localized strings plus the IDistributedCache implementation in order to cache out the localized strings. The flow is pretty simple,

  • whenever a localized string is requested it is firstly checked in the IDistributedCache
  • If the value for the key is not found in the cache, it is then read from the json file for the respective CultureInfo
  • When the value is retrieved from json file and it is valid, it's stored in the cache before returning it to the caller.

In this way the localized strings are cached only when requested and are physically stored in json files only.

Getting started

In Startup.cs make sure to add the localizer factory and the IStringLocalizer service with it's factory to create objects.

services.Configure<JsonLocalizerOptions>(Configuration.GetSection(nameof(JsonLocalizerOptions)));
services.AddSingleton<IStringLocalizerFactory, JsonStringLocalizerFactory>();
services.AddTransient(serviceProvider =>
{
    var factory = serviceProvider.GetRequiredService<IStringLocalizerFactory>();
    return factory.Create(null);
});

Installation

Checkout package description and installation instructions on nuget.org

About

A localization implementation using json files and DistributedCache for asp.net core

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •