GithubHelp home page GithubHelp logo

mihm / nginx_accept_language_module Goto Github PK

View Code? Open in Web Editor NEW

This project forked from giom/nginx_accept_language_module

0.0 0.0 0.0 72 KB

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

License: Other

nginx_accept_language_module's Introduction

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 ([email protected])

Acknowledgement

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

nginx_accept_language_module's People

Contributors

giom avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.