Eduardo Pisapia
Eduardo Pisapia

Reputation: 41

Ionic 1 / cordova how to get device language

Need help to get the Device language from my Ionic1 Application to set its idiom and translate the content on it.

I only find ways for Ionic 2, have tried with cordova plugis like cordova-globalization http://ngcordova.com/docs/install/ or https://github.com/apache/cordova-plugin-globalization but throw error with provider or doesn't found functions.

Thanks in advance

Upvotes: 0

Views: 1040

Answers (2)

Avinash Rathod
Avinash Rathod

Reputation: 610

If you are using language for "globalization" then -

First install plugin -> cordova plugin add cordova-plugin-globalization

then use -

navigator.globalization.getPreferredLanguage(function(language) {
   // This will display your device language
   console.log('language --',language);
 }, null);

For normal, you can use following to get device language

navigator.language || navigator.userLanguage

Upvotes: 0

Rai Vu
Rai Vu

Reputation: 1635

You could use the browser language: Check:

navigator.language || navigator.userLanguage

Upvotes: 1

Related Questions