Skip to content

It provides a mapping feature from a user's language to suitable language for a web site provider.

License

Notifications You must be signed in to change notification settings

sndyuk/nginx_select_lang_module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx HTTP Select Lang module

Chooses a suitable language from key-values and set it in the variable.

Installation

  1. Download it.
  2. Compile Nginx with:
$ ./configure --add-module=path/to/nginx_select_lang_module
$ make install

How it works

  1. Find user's selected language in the cookie name lang, e.g. lang=ja.
  2. If the cookie is not defined, find it in the Accept-Language header.
  3. Other than the avobe, use the second argument of the directive as a default language.
  4. Set the language to the variable name, it must start with $, e.g. $lang_selected, the first argument of the directive.

Form

<Select-lang-directive> ::= select_lang: <language-group> { " " <language-group> }

<language-group> ::= <langauge> { ":" <language> }

Example configuration:

  • $lang_selected is the name of a variable.
  • en, ja, zh-hans, zh-hant are available languages.
  • zh-hans is the representation of the following languages: zh-hans, zh, zh-cn, zh-sg:zh-tw.
  • zh-hant is the representation of the following languages: zh-hant, and zh-hk.
  • The first leftmost one en is the default language.
http {
  select_lang $lang_selected en ja zh-hans:zh:zh-cn:zh-sg:zh-tw zh-hant:zh-hk;
  server {
    location / {
      add_header X-Lang-Selected "$lang_selected";
      root /hoge/$lang_selected/index.html;
    }
  }
}

About

It provides a mapping feature from a user's language to suitable language for a web site provider.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages