javascript - Set locale on momentJS won't work - Stack Overflow

I've installed momentJS on ionicangular using bower - and it works fine. Except for changing loca

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

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

Share Improve this question asked Jan 2, 2016 at 22:05 AskbarAskbar 8991 gold badge7 silver badges11 bronze badges 2
  • 1 Did you load/include the lang file for fr? – t.niese Commented Jan 2, 2016 at 22:09
  • 1 of course - including the language file helps ;) thanx - feel free to post as answer – Askbar Commented Jan 3, 2016 at 8:24
Add a ment  | 

2 Answers 2

Reset to default 5

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.

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745076651a4609875.html

相关推荐

  • javascript - Set locale on momentJS won&#39;t work - Stack Overflow

    I've installed momentJS on ionicangular using bower - and it works fine. Except for changing loca

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信