Chooses a suitable language from key-values and set it in the variable.
- Download it.
- Compile Nginx with:
$ ./configure --add-module=path/to/nginx_select_lang_module
$ make install
- Find user's selected language in the cookie name
lang, e.g.lang=ja. - If the cookie is not defined, find it in the
Accept-Languageheader. - Other than the avobe, use the second argument of the directive as a default language.
- Set the language to the variable name, it must start with
$, e.g.$lang_selected, the first argument of the directive.
<Select-lang-directive> ::= select_lang: <language-group> { " " <language-group> }
<language-group> ::= <langauge> { ":" <language> }
$lang_selectedis the name of a variable.en,ja,zh-hans,zh-hantare available languages.zh-hansis the representation of the following languages:zh-hans,zh,zh-cn,zh-sg:zh-tw.zh-hantis the representation of the following languages:zh-hant, andzh-hk.- The first leftmost one
enis 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;
}
}
}