title: Getting the device language for a Phonegap application
body: <p>I'm developing an html5/JqueryMobile/Phonegap app. I have to detect the device language to redirect to a specific html. I'm trying to use Phonegap's <code>navigator.globalization.getPreferredLanguage</code>. On an iOS device it works fine. </p>
  
  <p>The code below detects the language "onDeviceReady" and performs the redirect. This code should be universal for iOS and Android but when I try it on an Android device it doesn't work. The screen freezes. What might cause this?</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Language&lt;/title&gt;
      &lt;script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" charset="utf-8"&gt;
  
  
          document.addEventListener("deviceready", onDeviceReady, false);
  
          function onDeviceReady() {
  
              navigator.globalization.getPreferredLanguage(
                                                           function (language)
                                                           {
  
                                                           if(language.value == "it")
                                                           {window.location.replace("index_it.html");}
                                                           else if (language.value == "ar")
                                                           {window.location.replace("index_ar.html");}
                                                           else 
                                                           {window.location.replace("index_en.html");}},
                                                           function ()
                                                           {
                                                           alert('Error getting language\n');
                                                           }
                                                           );
          }
  
  
          &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>