2

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

2
  • Any errors in the console? Commented Feb 25, 2016 at 13:19
  • Some solution? Same problem here. Commented Sep 25, 2016 at 2:21

2 Answers 2

2

You have it just with

window.navigator.userLanguage || window.navigator.language;
Sign up to request clarification or add additional context in comments.

2 Comments

i don't understand @Del
Sorry, I missuderstood the question. This answer is to get the language of the device / user without using the plugin. I leave this here in case they help you
0

First check the result of

if(typeof navigator.globalization !== "undefined") { 

If its false, the rest of the code will be skipped, because you dont have the plugin.

To get the plugin:

cordova plugin add cordova-plugin-globalization

5 Comments

no ,look please ( cordova plugin list com.atuhi.externalkeyboard 0.0.1 "External Keyboard" com.raananw.imageResizerTT 0.1.3 "ImageResizer" com.synconset.imagepicker 1.0.7 "ImagePicker" cordova-plugin-actionsheet 2.2.0 "ActionSheet" cordova-plugin-calendar 4.4.5 "Calendar" cordova-plugin-camera 1.2.0 "Camera" cordova-plugin-console 1.0.2-dev "Console" cordova-plugin-device 1.0.1 "Device" cordova-plugin-geolocation 1.0.1 "Geolocation" cordova-plugin-globalization 1.0.2 "Globalization"
Try: navigator.globalization.getPreferredLanguage( function (language) {alert('language: ' + language.value + '\n');}, function () {alert('Error getting language\n');} ); The github doc
!JavaScript ERROR: 'undefined' is not an object (evaluating 'navigator.globalization.getPreferredLanguage')
You use device or browser to test? Some of the cordova plugins wont work in browser, you need to run the app on device
i run the app on real device

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.