Bret
Bret
KPCKevin Powell - Community
Created by Bret on 9/11/2024 in #front-end
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?
7 replies