1

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?

NTP
  • 4,338
  • 3
  • 16
  • 24
OjamaYellow
  • 899
  • 1
  • 13
  • 27

2 Answers2

2

It worked after I added:

import * as moment from 'moment';
import 'moment/min/locales';
OjamaYellow
  • 899
  • 1
  • 13
  • 27
  • This works because the first statements loads the full version of moment, including all locales. You don't need the second statement. – Marc Oct 25 '18 at 08:26
1

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',
  },
},
Danielle Madeley
  • 2,616
  • 1
  • 19
  • 26