Code Monkey home page Code Monkey logo

identityserver3.contrib.localization's Introduction

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

  • Specific culture:
   var factory = new IdentityServerServiceFactory();
   var options = new LocaleOptions { LocaleProvider = env => "nb-NO" };

   factory.Register(new Registration<LocaleOptions>(options));   
   factory.LocalizationService = new Registration<ILocalizationService, GlobalizedLocalizationService>();
  • To use IdentityServer3s default provided localization fixed:
   var factory = new IdentityServerServiceFactory();
   factory.LocalizationService = new Registration<ILocalizationService, GlobalizedLocalizationService>();
  • To use Pirate culture:
   var factory = new IdentityServerServiceFactory();
   var options = new LocaleOptions { LocaleProvider = env => "pirate" };

   factory.Register(new Registration<LocaleOptions>(options));   
   factory.LocalizationService = new Registration<ILocalizationService, GlobalizedLocalizationService>();

  • Making use of the users language setting:
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:

  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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.