I'm doing a Phonegap hybrid app and i have to retrieve the device language, eg: "IT", "EN". Any suggestions on this?
Regarding your question the answers is:
var lang = navigator.language.split("-");
var current_lang = (lang[0]);
alert( "current_lang: " + current_lang );
There's (now) the Globalization API in Cordova to retrieve that kind of info (you can also get info for dates, currency, ...):
globalization.getPreferredLanguage
globalization.getLocaleName
globalization.dateToString
globalization.stringToDate
globalization.getDatePattern
globalization.getDateNames
globalization.isDayLightSavingsTime
globalization.getFirstDayOfWeek
globalization.numberToString
globalization.stringToNumber
globalization.getNumberPattern
globalization.getCurrencyPattern
See http://docs.phonegap.com/en/3.3.0/cordova_globalization_globalization.md.html#Globalization
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With