giom / nginx_accept_language_module Goto Github PK
View Code? Open in Web Editor NEWParse the Accept-Language header and sets a variable to a language you support that your user can understand
License: Other
Parse the Accept-Language header and sets a variable to a language you support that your user can understand
License: Other
A handy option, besides checking the accept language header, would be also to check an optional cookie value for a language code as well.
Maybe the following optional config statement:
accept_language_cookie <name of cookie to check>
And give the value of the cookie preference over the language order given in the accept language header.
This would allow the application to override the automagic language value (by setting a cookie), in case the uise would like to choose a language other than what their browser is set to.
For some major languages, 2-letter code is inadequate/insufficient.
Consider the Chinese language, which has 2 scripts, simplified and traditional. Those would be described as 5-character locale code zh-cn, zh-sg (simplified) and zh-tw, zh-hk (traditional).
It would be nice if your module could work with 5-character locale codes and some kind of user-defined locale-to-locale mapping.
You can see an example of my method I wrote in PHP Language Detector.
On review I noticed this module is prone to poor scalability.
Scales roughly O(n*m)
where n is the number of languages supplied in the header and m is the number of languages supported.
If m is sufficiently large this module will cease to perform well.
Does this module also have a way to add ", Accept-Language" to the Vary header -- or is there some good way to do this on nginx generally?
when building with the latest nginx release 1.27.0, build fails with
gcc -c -fPIC -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs -I src/http -I src/http/modules -I src/http/v2
-o objs/ngx_http_accept_language_module_modules.o
objs/ngx_http_accept_language_module_modules.c
./src/ngx_http_accept_language_module.c: In function ‘ngx_http_accept_language_variable’:
./src/ngx_http_accept_language_module.c:92:29: error: ‘ngx_http_headers_in_t’ has no member named ‘accept_language’
92 | if ( NULL != r->headers_in.accept_language ) {
| ^
./src/ngx_http_accept_language_module.c:93:26: error: ‘ngx_http_headers_in_t’ has no member named ‘accept_language’
93 | start = r->headers_in.accept_language->value.data;
| ^
./src/ngx_http_accept_language_module.c:94:32: error: ‘ngx_http_headers_in_t’ has no member named ‘accept_language’
94 | end = start + r->headers_in.accept_language->value.len;
| ^
make[1]: *** [objs/Makefile:1337: objs/addon/src/ngx_http_accept_language_module.o] Error 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.