Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locale not working #129

Open
capi1O opened this issue Jan 15, 2019 · 9 comments
Open

locale not working #129

capi1O opened this issue Jan 15, 2019 · 9 comments

Comments

@capi1O
Copy link

capi1O commented Jan 15, 2019

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');
  • additonal locales are correctly loaded : console.log(moment.localeData('es')); => durationLabels* keys are present
  • moment global locale is correctly set : console.log(moment(1316116057189).fromNow()); => spanish output
  • moment-duration-format still in english console.log(moment.duration(60, 's').format('s __')); => 60 seconds

versions :

  • moment 2.23.0
  • moment-duration-format 2.2.2
  • meteor 1.8 + react 16.5 if this matters.
@francbelak
Copy link

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.

@domhaas
Copy link

domhaas commented Feb 5, 2020

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
Copy link

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
Copy link

this does not work for me

@IS-Kuan
Copy link

IS-Kuan commented May 7, 2020

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
Copy link

usb248 commented May 18, 2020

Any updates ????

@ux-engineer
Copy link

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

@usb248
Copy link

usb248 commented Jun 2, 2021

Project is dead

@gersur
Copy link

gersur commented Jun 22, 2023

#124 (comment)

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

It's working for me

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants