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 🙂
Solution:
Change the language in browser settings
Jump to solution
6 Replies
Matvey
Matvey•4mo ago
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.
guerra
guerraOP•4mo ago
Can I do it in a react app? I mean checking the header It is just frontend not full stack
Matvey
Matvey•4mo ago
You can get the same info in from js in navigator.languages: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages
guerra
guerraOP•4mo ago
Thanks let me try How can I test it? Changing the header looks not working…
Solution
Matvey
Matvey•4mo ago
Change the language in browser settings
guerra
guerraOP•4mo ago
It works 🥰
Want results from more Discord servers?
Add your server