github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

giom / nginx_accept_language_module

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 7
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Parse the Accept-Language header and sets a variable to a language you support that your user can understand — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added some examples 
giom (author)
Wed Dec 17 06:57:50 -0800 2008
commit  02262ced73e91e933018a857908b96ea840d59aa
tree    badda2ae46bc592566f900dc025711b8dc5fde8a
parent  06b66da2fcd75f3e2f17f6b0af8f3525244968ea
nginx_accept_language_module /
name age
history
message
file LICENSE Mon Nov 10 10:48:17 -0800 2008 first commit [giom]
file README.textile Wed Dec 17 06:57:50 -0800 2008 Added some examples [giom]
file config Mon Nov 10 10:48:17 -0800 2008 first commit [giom]
directory src/ Fri Dec 05 09:33:31 -0800 2008 Fixed a bug where having a nil Accept-Language ... [giom]
README.textile

Nginx Accept Language module

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.

Syntax

set_from_accept_language $lang en ja pl; - `$lang` is the variable in which to store the locale - `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)

Caveat

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 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). In the situation where I’m using the module, this assumption works… but buyer beware :-)

Example configuration

If you have different subdomains for each languages
server { listen 80; server_name your_domain.com; set_from_accept_language $lang en ja zh; rewrite ^/(.*) http://$lang.your_domain.com redirect; }

Or you could do something like this, redirecting people coming to ‘/’ to /en (or /pt)

location / { set_from_accept_language $lang pt en; if ( $request_uri ~ ^/$ ) { rewrite ^/$ /$lang redirect; break; } }

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

Bugs

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

Acknowledgement

Thanks to Evan Miller for his guide on writing nginx modules (http://emiller.info/nginx-modules-guide.html)

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server