jsmreese/moment-duration-format

Locales always fallback to English

JulienDuf opened this issue · 6 comments

The locale keys used in this plugin are not implemented by moment. I had to implement my own locales to make it works in French.

Is it normal? If it is normal, maybe it would be a good idea to put the extra locales in the plugin.

Hi @JulienDuf, would you mind sharing how you loaded your own locales for moment-duration-format
?

const frLocale = {
    durationLabelsStandard: {
        S: "milliseconde",
        SS: "millisecondes",
        s: "seconde",
        ss: "secondes",
        m: "minute",
        mm: "minutes",
        h: "heure",
        hh: "heures",
        d: "jour",
        dd: "jours",
        w: "semaine",
        ww: "semaines",
        M: "mois",
        MM: "mois",
        y: "année",
        yy: "années"
    },
    durationLabelsShort: {
        S: "msec",
        SS: "msecs",
        s: "sec",
        ss: "secs",
        m: "min",
        mm: "mins",
        h: "hr",
        hh: "hrs",
        d: "jr",
        dd: "jrs",
        w: "sm",
        ww: "sms",
        M: "mo",
        MM: "mos",
        y: "an",
        yy: "ans"
    },
    durationTimeTemplates: {
        HMS: "h:mm:ss",
        HM: "h:mm",
        MS: "m:ss"
    },
    durationLabelTypes: [{ type: "standard", string: "__" }, { type: "short", string: "_" }],
    durationPluralKey: durationPluralKey
};

moment.updateLocale("fr", frLocale as any);

Thanks a lot ! Unfortunately I had already tried that to no avail. The output is still in english (I used moment.updateLocale("es", esLocale) but I also tried with the as any part added which did not compile. I will open a new issue.

Regarding this issue, include additional locales in moment-duration-format itself, this was asked in those issues : #106 & #116.

I did not read the code too deep, but I also experienced this issue and I wonder wan't it caused by

context.updateLocale('en', engLocale);

imho we should close this issue as the title is misleading and duplicates #106.

gersur commented

#124 (comment)

... you have to import moment-duration-format before changing the locale.

It's working for me

momentDurationFormatSetup(moment);
moment.locale("id");