Detecting language via JavaScript (i18n) best practices

Hey all! I have a site that uses navigator.languages to redirect a certain route to a locale-specific route (English to /en, Spanish to /es, Spanish (Latin America) to /es-latam, etc) and am curious about best practices. Using the Sensors/Location tab in Chrome, I am able to change locale to test that it works properly. It seems to be fine in this perfect environment, where navigator.languages only returns a single locale. However, I sent it to a friend in Mexico, and it defaulted to English for him. It turns out his browser has navigator.languages set to ['en-US', 'en', 'es']. In these cases, is it best to respect the browser's priority list, or to de-prioritize English locales in favor of other locales?
3 Replies
ἔρως
ἔρως4mo ago
if you don't have any state, start it with the value that the browser has after that, use whatever the user selected (bonus points if you persist it) you have no idea how annoying it is to use a website where you change language and that stupid piece of hot junk keeps changing the language to some broken half-assed barely readable bastardized version of my language
Bret
BretOP4mo ago
Makes sense! I do have a drop-down, will make sure that the state persists for future visits. Thanks 😄
ἔρως
ἔρως4mo ago
your users will thank you profusely using the debian website is an exercise in patience, and it is one of the websites that ruins something this basic
Want results from more Discord servers?
Add your server