Search code examples
androidcordovaionic-frameworkionic2ionic3

How can I get language of the android device in Ionic3, Cordova and Angular4 application?


I want to get the android device language from the app developed using Ionic3, Cordova and Angular4.

How can I get it?


Solution

  • You can use cordova-plugin-globalization which also offers an ionic-native wrapper. It offers a lot of useful methods, but you are probably looking for getPreferredLanguage() or getLocaleName().

    Installation:

    ionic cordova plugin add cordova-plugin-globalization
    npm install --save @ionic-native/globalization
    

    Example:

    import { Globalization } from '@ionic-native/globalization';
    constructor(private globalization: Globalization) { 
      this.globalization.getPreferredLanguage()
        .then(res => console.log(res))
        .catch(e => console.log(e));
    }