2

I have to build a localized application in JavaScript (jQuery Mobile, phonegap). Each time I ask the language(navigator.language) it returns me "en" even when I set the phone language on French or Spanish.

How can I detect the phone language instead of the navigator language which don't seem to change accordingly to phones?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Ernoriel
  • 89
  • 9
  • Although not detection, asking the user would be the safest bet. – Alex Jan 16 '12 at 11:40
  • It depends on the phone's OS; for example for Android, see http://stackoverflow.com/questions/4212320/get-the-current-language-in-device. – ChrisW Jan 16 '12 at 11:43
  • For Android, maybe this helps: http://stackoverflow.com/questions/6547642/get-the-language-of-user-in-android I don't know if a similar problem occurs on other OS. – Simon Jan 16 '12 at 11:44
  • Thanks a lot, the user-agent will do the trick on android. I'll test the navigator.language on Ios (language reference is not in the ios user-agent :s). I hope it will be ok. – Ernoriel Jan 16 '12 at 12:55

1 Answers1

1

It is not possible to detect the phone's language as far as I know. Using the user-agent or navigator.language are the only automated ways.

However, it is probably safest to just ask the user what language they speak.

rshea0
  • 11,769
  • 9
  • 27
  • 40
  • I'd realy like to ask the user but this idea was rejected. but it works fine with userAgent + navigator.language if there is no userAgent for compatibility reason. – Ernoriel Feb 16 '12 at 10:16