Auto select language react app
I'm not a front-end man, how can i have my website in english for all people outside my country? and my language if you open website from my country? I'm using react 🙂
6 Replies
The best way to add i18n (Internationalization) to a web app is to have specific urls for languages like
example.com/en
for English, example.com/de
for German, etc. Browses send accept-language
header with each request. If user goes to example.com
, you can check their language in accept-language
and redirect to a version of your site in this language.Can I do it in a react app? I mean checking the header
It is just frontend not full stack
You can get the same info in from js in
navigator.languages
: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languagesThanks let me try
How can I test it? Changing the header looks not working…
Solution
Change the language in browser settings
It works 🥰