You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{% for code, lang in languages %}
if ($http_accept_language ~* ^{{code}}) {
# Not safe, but it seems to work. May change depending on the outer directives.
set $lang {{code}};
}
{% endfor %}
can be replaced with:
map $http_accept_language $lang {
{% for code, lang in languages %}
^{{code}} {{code}};
{% endfor %}
default en;
}
which reduces the size of configuration (and let you avoid IFs).
You can make it even more interesting by composing a more complex RE with capture like: ^(?<language>(en|fr|de)) $language
Which will result in only two lines: one RE for languages and one default.
The text was updated successfully, but these errors were encountered:
Thanks for the tip! Unfortunately, a map can only be defined at the http level and this file is included at the server level. I have added the "not safe" comment recently to remind me it currently works because of the outer directives. Even fixed, it's still not a correct solution if your preferred language is not one supported but you have another language as a fallback. A solution would be this C module (https://github.com/giom/nginx_accept_language_module/) or an alternative Lua implementation.
vincent.bernat.ch/layout/nginx.j2
Line 50 in b1fd00d
this part:
can be replaced with:
which reduces the size of configuration (and let you avoid IFs).
You can make it even more interesting by composing a more complex RE with capture like:
^(?<language>(en|fr|de)) $language
Which will result in only two lines: one RE for languages and one default.
The text was updated successfully, but these errors were encountered: