MomentJS with react languages

Viewed 2575

I'm using moment JS with React and I have a problem with changing language. When I type moment.lang('pl') or moment.locale('pl') and then moment.format('MMMM') it only shows month in english. Is there any way to fix it?

Code

import React, {Component} from 'react';
import moment from 'moment';


class Time extends Component {
    constructor(props) {
        super(props);


        this.state = {}
    }


    render() {

        let march = moment();

        moment.lang('pl');

        console.log(march.format('MMMM'));

        return (
            <div>
                <div className="time">
                    <br/>
                </div>
            </div>
        )
    }
}
export default Time;
2 Answers

Just adding to Natsathorn's answer, you can import it dynamically with

import(`moment/locale/${navigator.language.toLocaleLowerCase()}`).then();
Related