Angular: Changing locale in moment has no effect

6.5k views Asked by At

I use angular2-moment for handling dates in my app. I have one component that is used like datepicker with help of moment, now I am doing localization and I am stuck with localizing moment. I wrote:

console.log(moment().locale('de').format('LLLL'));

in my constructor to check but I still get english version. Is there any special imports I need to do so this will work?

2

There are 2 answers

1
OjamaYellow On BEST ANSWER

It worked after I added:

import * as moment from 'moment';
import 'moment/min/locales';
0
Danielle Madeley On

I'm having what might be the same issue. For a reason I can't figure out, locale files from webpack are empty.

One workaround I've found is to alias moment to moment/min/moment-with-locales. It's not ideal but it gets working locales again.

resolve: {
  modules: ['node_modules', ],
  extensions: ['.js', '.jsx', '.react.js'],
  mainFields: ['browser', 'jsnext:main', 'main'],
  alias: {
    // Ensure our moment is locale enabled.
    moment: 'moment/min/moment-with-locales',
  },
},