Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova / Phonegap Globalization vs. navigator.language

I want to implement some mechanism to automatically selecting UI language for my Cordova application. The application is also served from the web (i.e. browser).

From what I see, I can either use the Cordova globalization API plugin (here) or, it seems that both Android and iOS support navigator.language which give the device language.

Is there any reason I should opt to use the Cordova plugin over the built in browser/Web View property?

Thanks!

like image 245
Tomer Cagan Avatar asked Oct 18 '22 19:10

Tomer Cagan


1 Answers

After a series of searches and tests on real devices I can say that the two methods to retrieve the language of the device are more or less the same except for two small differences:

  • on iOS devices the user can choose separately the language and the region of the device. So, for example, it can choose as a language italian but as region USA. In this situation, the plugin will return the string it-US differently by the navigator.language property which will return the string it-IT (tested on iOS 11). If you have to know just the language this isn’t a big problem.
  • On Android, there is a bug because of which the navigator.language is not immediately updated. The new setting is available only after the application is killed. The plugin does not suffer os this bug. A workaround could be to use the navigator.languages property which is correctly updated (tested on Android 5.0.2).

If you have to know just the language you can use the information provided by navigator object without any problem.

like image 154
LuckyStarr Avatar answered Oct 20 '22 11:10

LuckyStarr