• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H30-Oct-2018-137108

.gitignoreH A D30-Oct-20186 11

LICENSEH A D30-Oct-20181.3 KiB2625

README.mdH A D30-Oct-20181.8 KiB6442

configH A D30-Oct-2018417 1210

README.md

1# Nginx Accept Language module
2
3This module parses the `Accept-Language` header and gives the most suitable locale for the user from a list of supported locales from your website.
4
5## Install in CentOS 7
6
7```
8yum -y install https://extras.getpagespeed.com/release-el7-latest.rpm
9yum -y install nginx-module-accept-language
10```
11
12## Syntax
13
14    set_from_accept_language $lang en ja pl;
15
16* `$lang` is the variable in which to store the locale
17* `en ja pl` are the locales supported by your website
18
19If none of the locales from `Accept-Language` is available on your website, it sets the variable to the first locale of your website's supported locales (in this case, `en`).
20
21## Caveat
22
23It currently assumes that the `Accept-Language` is sorted by quality values (from my tests it's the case for safari, firefox, opera and ie) and discards q (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).
24In the situation where I'm using the module, this assumption works... but buyer beware :-)
25
26## Example configuration
27
28If you have different subdomains for each languages
29
30```
31server {
32    listen 80;
33    server_name your_domain.com;
34    set_from_accept_language $lang en ja zh;
35    rewrite ^/(.*) http://$lang.your_domain.com redirect;
36}
37```
38
39
40Or you could do something like this, redirecting people coming to '/' to /en (or /pt):
41
42```
43location / {
44    set_from_accept_language $lang pt en;
45     if ( $request_uri ~ ^/$ ) {
46       rewrite ^/$ /$lang redirect;
47       break;
48     }
49}
50```
51
52
53## Why did I create it?
54
55I'm using page caching with merb on a multi-lingual website and I needed a way to serve the correct language page from the cache
56I'll soon put an example on http://gom-jabbar.org
57
58## Bugs
59
60Send Bugs to Guillaume Maury (dev@gom-jabbar.org)
61
62## Acknowledgement
63
64Thanks to Evan Miller for his [guide on writing nginx modules](http://emiller.info/nginx-modules-guide.html).