javascriptangularjsionic-frameworkmomentjs

Set locale on momentJS won't work


I've installed momentJS on ionic/angular using bower - and it works fine. Except for changing locale to 'fr' or 'da'. The files are available in the locales-folder, but the following code still echoes in english :(

moment.locale('fr');
var NowMoment = moment().format("dddd, MMMM Do");
console.log(NowMoment);

It's written in my directive/link function. Should I do anything different ?

Thanx Ask


Solution

  • moment.js itself does not load any language files. So as long as you do not use moment+locales.js (which would contain all locals) you will either need to include the additional language data with your moment.js or you need to load it separate.

    So either something like this:

    <script src="/js/moment+fr.js"></script>
    

    Or this that way:

    <script src="/js/moment.js"></script>
    <script src="/js/locale/fr.js"></script>
    

    If you only use fr then you would not need to call moment.locale('fr'); in this particular case, because the last loaded local will be the active one.