Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap iOS retrieve device language

Tags:

ios

cordova

I'm doing a Phonegap hybrid app and i have to retrieve the device language, eg: "IT", "EN". Any suggestions on this?

like image 613
Yazo Avatar asked Dec 01 '22 21:12

Yazo


2 Answers

Regarding your question the answers is:

 var lang = navigator.language.split("-");
 var current_lang = (lang[0]);
 alert( "current_lang: " + current_lang );
like image 82
Sumanth Avatar answered Dec 15 '22 12:12

Sumanth


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

like image 35
user276648 Avatar answered Dec 15 '22 10:12

user276648