Search code examples
iphoneandroidiosmobile-website

How do i get the native language localisation on a smartphone from browser javascript?


I'm working on a mobile website and I want to change languages by the phone native defaults.

Is there any solution to do it? I mean there are three states:

  1. the phone lang setting is "eng"
  2. the phone lang setting is "hun"
  3. the phone lang setting is other foreign lang, then the website lang is "eng"

I want to use it on iOS and Android too.

Thx


Solution

  • in case you are still interested in an answer:
    you can use navigator.appVersion, see the following JavaScript snippet:

      <script type="text/javascript">
        alert(navigator.appVersion);
      </script>
    

    and the corresponding result on a Android device with Android 2.2:
    screenshot
    you just have to parse for the language, in the example it is de-de.
    Sorry, I do not have an iPhone, but the result is probably similar...