jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
967 stars 121 forks source link

Locales always fallback to English #126

Open JulienDuf opened 5 years ago

JulienDuf commented 5 years ago

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.

capi1O commented 5 years ago

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

JulienDuf commented 5 years ago
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);
capi1O commented 5 years ago

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 : https://github.com/jsmreese/moment-duration-format/issues/106 & https://github.com/jsmreese/moment-duration-format/issues/116.

olegstepura commented 5 years ago

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

https://github.com/jsmreese/moment-duration-format/blob/0d6cfe1094a74f02038237bce19c4cf1d79bada3/lib/moment-duration-format.js#L1660

Serrulien commented 4 years ago

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

gersur commented 1 year ago

https://github.com/jsmreese/moment-duration-format/issues/124#issuecomment-770070357

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

It's working for me

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