jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
968 stars 120 forks source link

locale not working #129

Open capi1O opened 5 years ago

capi1O commented 5 years ago
import moment from 'moment';
import 'moment/locale/es';
import momentDurationFormatSetup from 'moment-duration-format';
momentDurationFormatSetup(moment);

moment.updateLocale('es', {
    durationLabelsStandard: {
        "S": "milisegundo",
        "SS": "milisegundos",
        "s": "segundo",
        "ss": "segundos",
        "m": "minuto",
        "mm": "minutos",
        "h": "hora",
        "hh": "horas",
        "d": "día",
        "dd": "días",
        "w": "semana",
        "ww": "semanas",
        "M": "mes",
        "MM": "meses",
        "y": "año",
        "yy": "años"
    },
   ...
});
moment.locale('es');

versions :

francbelak commented 4 years ago

Hi,

I do not know if this is somehow language specific but in my case it does work fine with "de".

import moment from 'moment';
import 'moment/locale/de'
import 'moment-duration-format';

moment.locale('de');
moment.updateLocale('de ', {
  durationLabelsStandard: {
    S: 'Millisekunde',
    SS: 'Millisekunden',
    s: 'Sekunde',
    ss: 'Sekunden',
    m: 'Minute',
    mm: 'Minuten',
    h: 'Stunde',
    hh: 'Stunden',
    d: 'Tag',
    dd: 'Tage',
    w: 'Woche',
    ww: 'Wochen',
    M: 'Monat',
    MM: 'Monate',
    y: 'Jahr',
    yy: 'Jahre'
  },
});

const start = moment('2020-01-30', 'YYYY-MM-DD');
const end = moment('2020-01-31', 'YYYY-MM-DD');
const difference = moment.duration(end.diff(start));
const duration = difference.format();
console.info(duration); // --> outputs 1 Tag

Versions:

Maybe it has already been fixed in the meantime.

domhaas commented 4 years ago

Hi,

I do not know if this is somehow language specific but in my case it does work fine with "de".

import moment from 'moment';
import 'moment/locale/de'
import 'moment-duration-format';

moment.locale('de');
moment.updateLocale('de ', {
  durationLabelsStandard: {
    S: 'Millisekunde',
    SS: 'Millisekunden',
    s: 'Sekunde',
    ss: 'Sekunden',
    m: 'Minute',
    mm: 'Minuten',
    h: 'Stunde',
    hh: 'Stunden',
    d: 'Tag',
    dd: 'Tage',
    w: 'Woche',
    ww: 'Wochen',
    M: 'Monat',
    MM: 'Monate',
    y: 'Jahr',
    yy: 'Jahre'
  },
});

const start = moment('2020-01-30', 'YYYY-MM-DD');
const end = moment('2020-01-31', 'YYYY-MM-DD');
const difference = moment.duration(end.diff(start));
const duration = difference.format();
console.info(duration); // --> outputs 1 Tag

Versions:

* "moment": "^2.24.0",

* "moment-duration-format": "^2.3.2",

Maybe it has already been fixed in the meantime.

Can confirm that localization works on these versions.

Anyhow, I doesn't work with Unit labels like this y [years], M [months]

With underscore or double underscores it works perfectly: m __

ghdoergeloh commented 4 years ago

The Problem seems to be caused by momentDurationFormatSetup. I just deleted this method from my code an it worked:

import moment from 'moment'
import 'moment-duration-format'
import 'moment/locale/de'
sibelius commented 4 years ago

this does not work for me

IS-Kuan commented 4 years ago

Exactly the same problem with latest versions (moment.js 2.25.3 + moment.duration-format 2.2.2) I also tried the versions around Dec 2017, still the same bug. (moment.js 2.19.3 + moment.duration-format 2.1.0)

usb248 commented 4 years ago

Any updates ????

ux-engineer commented 3 years ago

Would be nice to have locale switching working - any solutions?

usb248 commented 3 years ago

Project is dead

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");