Question

How can I get all the language strings that comply to the returned value of the success function parameter that is passed when calling:

navigator.globalization.getPreferredLanguage(
  function (language) {alert('language: ' + language.value + '\n');},
  function () {alert('Error getting language\n');}
);

source

When I run this code on my Android devices I get "English", however in some places I read that it returns the name of the language in the original language, for example, it will return '中国的' for Chinese.

I need this returned value in order to change the UI language.

Was it helpful?

Solution

I'd use the function getLocaleName for this, and then use the first two chars given. The values given can be found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top