Search code examples
angularjscordovaionic-frameworkglobalization

how to get language of device with cordova angularjs?


i want to include the navigator.globalization so i use this tutorial enter link description here

this code:

.run(function($ionicPlatform, $translate) {
        $ionicPlatform.ready(function() {
            if(typeof navigator.globalization !== "undefined") {
                navigator.globalization.getPreferredLanguage(function(language) {
                    $translate.use((language.value).split("-")[0]).then(function(data) {
                        alert("SUCCESS -> " + data);
                    }, function(error) {
                        alert("ERROR -> " + error);
                    });
                }, null);
            }
        });

my problem ,this code the alert is not displayed


Solution

  • You have it just with

    window.navigator.userLanguage || window.navigator.language;