How can I change Chrome settings to test using navigator.language
Solution 1
As of Sept 2021, on Mac (M1):
To change window.navigator.language
:
- Settings > Advanced > Language > Add Language
- then bring this language to the top
To change the language of the user interface:
(thanks to @AdamBittlingmayer above)
defaults write com.google.Chrome AppleLanguages '(es, es-ES)'
To verify:
defaults read com.google.Chrome
Solution 2
Use chrome://settings/languages#lang and (important) make sure that the language you selected is the top choice (the preferred language).
More information: https://alicoding.com/detect-browser-language-preference-in-firefox-and-chrome-using-javascript/
Solution 3
On MacOS, the Chrome UI language (window.navigator.language
) cannot be set via chrome://settings/languages or even via the --lang
command line argument (like on Windows) or environment variables (like on Linux).
The browser accept languages (window.navigator.languages
array, note the final s) can be set via chrome://settings/languages and thus via ChromeDriver options.
Therefore, besides manually changing the system language for the OS user, the only option remaining is the -AppleLanguages
flag.
For example, to Spanish:
defaults write com.google.Chrome AppleLanguages '(es, es-ES)'
To verify:
defaults read com.google.Chrome
This is the situation as of Chrome build 58.0.3029.110.
Solution 4
In the meantime, there is a generic description how to test locales in Chrome: https://developer.chrome.com/extensions/i18n#locales-testing
Related videos on Youtube
Max Heiber
Updated on June 04, 2022Comments
-
Max Heiber almost 2 years
I'm trying to internationalize an app and need to test how it behaves in other locales.
However,
navigator.language
always returnsen-US
, even if I change language settings in both Chrome and OS X.What can I do to the browser to force
navigator.language
to return something likees-MX
?Clarification
I'm trying to make the change as a user, through the GUI, not with code.
-
Krupal Patel almost 6 yearsyeah, ensure that you keep language on the TOP.
-
adamdport over 5 yearsI apparently misclicked and didn't realize I downvoted you until a day later. Now it won't let me undo it. I'm sorry!