$translateProvider.preferredLanguage and cordova globalisation


#1

I need to load a static file based on the system language to achieve that I do use angular-translate and Cordova globalization but as it’s known navigator.globalization.getPreferredLanguage must be called inside ionic.Platform.ready which imply that the language doesn’t imply :dizzy_face: (normal I think !).

Code :

.config(['$translateProvider', function ($translateProvider) {

    // configures staticFilesLoader
    $translateProvider.useStaticFilesLoader({
      prefix: 'translations/locale-',
      suffix: '.json'
    });



    ionic.Platform.ready(function () {
      console.log('ionic.Platform.ready');
      navigator.globalization.getPreferredLanguage(
        function (language) {
          console.log(language.value);

          preferredlanguage = language.value;
          // load 'en' table on startup
          $translateProvider.preferredLanguage(preferredlanguage);
        },
        function ($translateProvider) {
          preferredlanguage = 'fr-FR';
          // load 'en' table on startup
          $translateProvider.preferredLanguage(preferredlanguage);
        }
      );

    });
  }]);