I made this website with english default language, and french as second language.
Unfortunately (as a french), when I go on the website (with french browser/OS), it doesn’t detect the language and show me the english version.
How can I enable language detection then?
Please note that it’s hosted on Netlify.
It seems need to use JS to write cookie and manage it
Both the language and the country can be specified in a cookie as well ( nf_lang and nf_country respectively), so you can override the default behavior with JavaScript
In fact, it’s normal to use dynamic language (as JS, PHP, …) because you need to detect supported lang and redirect to same lang version.
Ce qui n’est pas mon cas.
Suis sous OpenBSD 6.6, session en fr_FR, interfaces régionalisées en FR pour Firefox v69.0.2, et Chromium v79.0.3945.88, mais j’obtiens la version EN !
Et, bien sûr, je vis en France.
It’s not my case.
I run Firefox v69.0.2, and Chromium v79.0.3945.88, GUI i18n FR, on OpenBSD stable 6.6, with lang session in fr_FR, but your site is delivered into EN!
And, I live in France.
// Create cookie to get the Browser Language
const userLang = navigator.language || navigator.userLanguage;
document.cookie = `nf_lang = ${userLang}`;
& I just rewrite these redirects and it seems to work (‘language = fr’ alone doesn’t work) !
# Redirect users with french language preference from / to /fr
/ /fr/ 302 Language=fr
/ /fr/ 302 Language=fr-be
/ /fr/ 302 Language=fr-ca
/ /fr/ 302 Language=fr-ch
/ /fr/ 302 Language=fr-fr
/ /fr/ 302 Language=fr-lu
/ /fr/ 302 Language=fr-mc
The only problem is when I click on “Pardon my french” to go to the english version, it redirects to the French version logically. So I can’t access the other language anymore.
How would you fix this?
Also, I couldn’t load the images & css at first because all URLs were re-written with /fr/.
I had to change it but it’s not perfect. How would you do ?
/* /fr/:splat 302 Language=fr # Was re-writing all assets with /fr/
/ /fr/ 302 Language=fr # work only with the homepage
I have only one page now, but might have several pages later.
How would you use the * & :splat without affecting the assets so they can load properly ?
I still have the issue, when I click on button (Pardon My French button) to switch to the English version, it keeps redirecting to the french version : www.sabir.paris/.
but the stylesheets & assets were not loading because their URL was modified too (I did a translation by directory).
Here’s what I have : <link type="text/css" rel="stylesheet" href="{{ .Site.BaseURL }}css/app.css">
I don’t know why but the redirection by language doesn’t work anymore.
If i list my cookies in the console, I have nf_lang=fr-FR but it still redirects me to the english version.
I have set defaultContentLanguageInSubdir = true and my _redirects file lools like this :
Redirect users with french language preference from / to /fr
/ /fr/ 302 Language=fr
/ /fr/ 302 Language=fr-be
/ /fr/ 302 Language=fr-ca
/ /fr/ 302 Language=fr-ch
/ /fr/ 302 Language=fr-fr
/ /fr/ 302 Language=fr-lu
/ /fr/ 302 Language=fr-mc
/ /en/ 302
Apparently we are both stuck with the same problem and from what I have read those past few days the reason is : Netlify does not understand if your request has multiple languages set in the request.
That is why some will say they are redirected and others don’t