IdentityServer3.Contrib.Localization icon indicating copy to clipboard operation
IdentityServer3.Contrib.Localization copied to clipboard

Localization support for IdentityServer3

master dev latest
master dev NuGet Stable

Contents

Implementation of IdentityServerV3's ILocalizationService.

What does it translate?

  • Resource strings defined by IdentityServer. See a list of defined resources here.
  • If what you want to translate is not defined by those resources, you would need to implement it yourself.

Usage

  • Set a specific culture for all users:
   var factory = new IdentityServerServiceFactory();
   var options = new LocaleOptions { LocaleProvider = env => "nb-NO" };

   factory.Register(new Registration<LocaleOptions>(options));   
   factory.LocalizationService = new Registration<ILocalizationService, GlobalizedLocalizationService>();
  • Making use of the users language setting from the browser:
using System.Net.Http.Headers; // if you want to use StringWithQualityHeaderValue
 

  var opts = new LocaleOptions
  {
      LocaleProvider = env =>
      {
          var owinContext = new OwinContext(env);
          var owinRequest = owinContext.Request;
          var headers = owinRequest.Headers;
          var accept_language_header = headers["accept-language"].ToString();
          var languages = accept_language_header
                              .Split(',')
                              .Select(StringWithQualityHeaderValue.Parse)
                              .OrderByDescending(s => s.Quality.GetValueOrDefault(1));
         var locale = languages.First().Value;
         return locale;
      }
  };
  
  factory.Register(new Registration<LocaleOptions>(opts));
  factory.LocalizationService = new Registration<ILocalizationService, GlobalizedLocalizationService>();

Supported languages

Install

  PM> Install-Package IdentityServer3.Localization

NuGet: https://www.nuget.org/packages/IdentityServer3.Localization

Contributing

How to add another language:

  • Fork the repo
  • Add the following resource files for your language in the resource folder (for instance by copying the default). ISO codes can be found [here])https://msdn.microsoft.com/en-us/library/ee796272(v=cs.20).aspx)
  1. Events.ISO-code-for-your-translation.resx
  2. Messages.ISO-code-for-your-translation.resx
  3. Scopes.ISO-code-for-your-translation.resx
  • Run the tests and fix any errors so they are green!
  • Rebase off upstream if behind, and submit the Pull Request

Dependencies

  • Thinktecture.IdentityServer3 - http://www.nuget.org/packages/Thinktecture.IdentityServer3/