Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change Chrome settings to test using navigator.language

I'm trying to internationalize an app and need to test how it behaves in other locales.

However, navigator.language always returns en-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 like es-MX?

Clarification

I'm trying to make the change as a user, through the GUI, not with code.

like image 231
Max Heiber Avatar asked Mar 17 '16 22:03

Max Heiber


People also ask

What is navigator language?

The Navigator language property is used for returning the browser's language version. It is a read-only property and it returns a string representing the language version of the browser. Some of the possible language codes are : en-US.

Why is Chrome showing a different language?

To check your Google Account language, open your Google Account. You'll find the language you selected. The language change didn't work: If your Google Account doesn't match the language you selected, clear your browser's cache and cookies and set the language again.

How do you change the Inspect language?

# Use DevTools in your preferred languageOpen Settings, then select your preferred language under the Preferences > Language dropdown and reload DevTools.


Video Answer


2 Answers

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/

like image 109
Tracysss Avatar answered Oct 05 '22 19:10

Tracysss


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.

like image 40
Adam Bittlingmayer Avatar answered Oct 05 '22 21:10

Adam Bittlingmayer