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

Implement locale inheritance and locale updating #2774

Closed
wants to merge 1 commit into
base: develop
from

Conversation

Projects
None yet
5 participants
@ichernev
Contributor

ichernev commented Nov 27, 2015

Users have requested this in one way or another.

Locale inheritance

Now, you can write

moment.defineLocale('en-foo', {
  parentLocale: 'en',
  /* */
});

which would create a new locale en-foo, taking as base the en locale and modifying the specified properties. Providing an object field (like calendar) will update only the supplied fields, the rest will be inherited. (for exampe specifying calendar: {sameDay: '...'}, will update sameDay, but keep nextDay and the other calendar attributes).

Locale update

moment.updateLocale('en', {
  /**/
});

This has similar semantics to inheritance, but changes the specified locale, instead of creating a new one. Actually the original locale is not changed but a new one with the same name created. This means existing moments using the updated locale won't change behavior.

Use

moment.updateLocale('en', null);

To revert an update. If there are no applied updates this removes the locale.

TODO:

  • make a proper base English locale, make other locales inherit from it behind the scenes
@ichernev

This comment has been minimized.

Show comment
Hide comment
@ichernev

ichernev Dec 9, 2015

Contributor

@icambron @mj1856 any comments on this?

Contributor

ichernev commented Dec 9, 2015

@icambron @mj1856 any comments on this?

@icambron

This comment has been minimized.

Show comment
Hide comment
@icambron

icambron Dec 9, 2015

Member

Looks good to me.

Member

icambron commented Dec 9, 2015

Looks good to me.

@ichernev

This comment has been minimized.

Show comment
Hide comment
@ichernev

ichernev Mar 6, 2016

Contributor

Merged in 78bfe90

Contributor

ichernev commented Mar 6, 2016

Merged in 78bfe90

@Aditya28268

This comment has been minimized.

Show comment
Hide comment
@Aditya28268

Aditya28268 Jun 23, 2016

when I m using moment.js in my simple html page getting "Deprecation warning: use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale " how can I fixed it ..?

Aditya28268 commented Jun 23, 2016

when I m using moment.js in my simple html page getting "Deprecation warning: use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale " how can I fixed it ..?

@maggiepint

This comment has been minimized.

Show comment
Hide comment
@maggiepint

maggiepint Jun 23, 2016

Member

@Aditya28268 if you are updating an existing locale, just use .updateLocale instead of .locale

Member

maggiepint commented Jun 23, 2016

@Aditya28268 if you are updating an existing locale, just use .updateLocale instead of .locale

@Aditya28268

This comment has been minimized.

Show comment
Hide comment
@Aditya28268

Aditya28268 Jun 24, 2016

Hello ,

I'm not using ".locale" in my code or not updating any existing locale .
I'm just trying to include your moment.js library. But then the
deprecation warning occurs.
How can I remove this warning. Or it is a library issue?
Please suggest.

On Thursday 23 June 2016 10:42 PM, Maggie Pint wrote:

@Aditya28268 https://github.com/Aditya28268 if you are updating an
existing locale, just use .updateLocale instead of .locale


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2774 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ARBDTCI6qIq2hKSwTy8ToI9Qw-V1EHftks5qOr6VgaJpZM4GqSvu.

Warm Regards,

Aditya Singh Tomar

Aditya28268 commented Jun 24, 2016

Hello ,

I'm not using ".locale" in my code or not updating any existing locale .
I'm just trying to include your moment.js library. But then the
deprecation warning occurs.
How can I remove this warning. Or it is a library issue?
Please suggest.

On Thursday 23 June 2016 10:42 PM, Maggie Pint wrote:

@Aditya28268 https://github.com/Aditya28268 if you are updating an
existing locale, just use .updateLocale instead of .locale


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2774 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ARBDTCI6qIq2hKSwTy8ToI9Qw-V1EHftks5qOr6VgaJpZM4GqSvu.

Warm Regards,

Aditya Singh Tomar

@icambron

This comment has been minimized.

Show comment
Hide comment
@icambron

icambron Jun 24, 2016

Member

Hi Aditya, two quick things: 1. please don't post issues at the bottom of other issues; it creates a hassle for us and makes it harder for people who care about the issue here to find out what they want. 2. You might have better luck posting on SO or chatting with us on Gitter. The warning you're seeing isn't something that we expect to see, so it's not really possible for us to help without knowing more about what you've done, and getting to the bottom of it in Github tickets is a painful way to do that.

Member

icambron commented Jun 24, 2016

Hi Aditya, two quick things: 1. please don't post issues at the bottom of other issues; it creates a hassle for us and makes it harder for people who care about the issue here to find out what they want. 2. You might have better luck posting on SO or chatting with us on Gitter. The warning you're seeing isn't something that we expect to see, so it's not really possible for us to help without knowing more about what you've done, and getting to the bottom of it in Github tickets is a painful way to do that.

@casvil

This comment has been minimized.

Show comment
Hide comment
@casvil

casvil Apr 12, 2018

I am using the moment.updateLocale function and I keep getting the following error:

Property updateLocale does not exist on type Moment. or Property updateLocale does not exist on type typeof moment.

https://momentjs.com/guides/#/warnings/define-locale/

casvil commented Apr 12, 2018

I am using the moment.updateLocale function and I keep getting the following error:

Property updateLocale does not exist on type Moment. or Property updateLocale does not exist on type typeof moment.

https://momentjs.com/guides/#/warnings/define-locale/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment