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

  • 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:

  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

identityserver3.contrib.localization's People

Contributors

bghveding avatar chriszhang03 avatar cocoke2002 avatar dalager avatar devlz303 avatar fdipuma avatar ghys avatar gustavoruscitto avatar heavenwing avatar iltera avatar janslahar avatar jdomaga avatar johnkors avatar julianpaulozzi avatar kenvangilbergen avatar leastprivilege avatar liteolika avatar manuelrauber avatar mniak avatar osmanmelsayed avatar petr-k avatar samcook avatar totpero avatar vidarkongsli avatar yuxiaochou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

identityserver3.contrib.localization's Issues

Views localization support for IdentityServer3

I borrowed the prefix of this project because I want this house organized to take part of this project IdentityServer3.Contrib.ViewLocalization.

Basically it's a angular way to translate the view based on the language requested by the browser and allowing user to change the language on demand.

After I talk more about it, but in the meantime I think already ready for viewing and testing.

How to get started translating IdentityServer3

@johnkors you asked me to help translating IdentityServer.
I'm will to do the English => Dutch translation, but I have no clue how to get started.

And I'm wondering if anyone would use the dutch translation. Everyone here, got English as a required subject in high school.

Detect current language

Does this detect the current language of the user and switch?
Or just enables to set a default language at startup?

Original strings missing

This repository seems to be missing the original strings which makes it harder than it ought to be to translate.

IdnetityServer.Localization not working

I am using IdentityServer3 v2.6 and IdentityServer3.Localization v0.3.194

I have created a custom LocaleOptions class,

   public class BrowserLanguageOptionsSelector : LocaleOptions
    {
        public BrowserLanguageOptionsSelector()
        {
            LocaleProvider = env =>
            {
                var owinContext = new OwinContext(env);
                var owinRequest = owinContext.Request;
                var headers = owinRequest.Headers;
                var acceptLanguageHeader = headers["accept-language"].ToString();
                var languages = acceptLanguageHeader
                    .Split(',')
                    .Select(StringWithQualityHeaderValue.Parse)
                    .OrderByDescending(s => s.Quality.GetValueOrDefault(1));
                var locale = languages.First().Value;
                return locale;
            };
        }
    }

And setted factory options like this:

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

But this does not work. When I try different language browsers, it show only English alnguage options.

When I set breakpoint in

LocalProvider = env

line, it breaks,
but when I set breakpoint in

var owinContext = new OwinContext(env);

line, it does not break. I mean it does not go into env method.

I used specific culture like this:

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

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

But did not worked.

change language

I have a multilingual Identity server
how can I change culture in run time ?
if I set culture in configuration time so ti wont change in run time
I think it should be change by current culture

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.