Askbar
Askbar

Reputation: 889

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

Upvotes: 3

Views: 4725

Answers (2)

Aldo Jimenez
Aldo Jimenez

Reputation: 1

When working with TypeScript

import moment from 'moment/moment';
import 'moment/locale/es';

moment.locale('es');

locale function wouldn't change the language You will need to explicitly call the js library

import moment from 'moment/moment.js';

and this will do the magic.

Upvotes: 0

t.niese
t.niese

Reputation: 40882

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.

Upvotes: 5

Related Questions