Search code examples
jsonangularjsdatepickerlocaleangular-translate

Use angular translate static-loader-file for date picker (with several locale files)


I need to translate the angular date picker. I've installed angular-translate-loader-static-files, downloaded locale files and included the index.html.

<script src="external/angular-translate-loader-static-files-master/angular-translate-loader-static-files.min.js"></script>

also added this part in app.js

 $translateProvider.useStaticFilesLoader({ 
    prefix: 'locale/angular-locale_',
    suffix: '.js'
});

But as a fact - js file that is the last declared in index.html ( ) is used when switch between languages. So, if change the order <script src="external/locale/angular-locale_en.json"></script> <script src="external/locale/angular-locale_es.json"></script>, then 'es' will be used for date picker.

Locales are able to be downloaded here: https://github.com/angular/angular.js/tree/master/src/ngLocale


Solution

  • You need to set you preferred language, so something like

    $translateProvider.preferredLanguage('en');
    

    Not sure what you want your preferred language to be but setting a default will help.