FAQ

Page Discussion Edit History

AcceptLanguageModule

Contents

[edit] nginx_accept_language_module

This module is not distributed with the Nginx source. See the installation instructions.

Available on github at [1]

[edit] Description

This module parses the Accept-Language header and gives the most suitable locale for the user from a list of supported locales from your website.

[edit] Example configuration

set_from_accept_language $lang en ja pl;

where $lang is the variable in which to store the locale and en ja pl are the locales supported by your website

If 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).

Note: It 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 [2]). In the situation where I'm using the module, this assumption works... but buyer beware :-)

[edit] Installation

Download the module source from github.

Unpack, and then compile nginx with:

./configure --add-module=path/to/nginx_accept_language_module

[edit] Why did I create it?

I'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 I'll soon put an example on http://gom-jabbar.org

[edit] Bugs

Send Bugs to Guillaume Maury (dev@gom-jabbar.org)

[edit] Credits

Thanks to Evan Miller for his guide on writing nginx modules.