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

Implement locale inheritance and locale updating #2774

Closed
wants to merge 1 commit into from

Conversation

ichernev
Copy link
Contributor

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

ichernev commented Dec 9, 2015

@icambron @mj1856 any comments on this?

@icambron
Copy link
Member

icambron commented Dec 9, 2015

Looks good to me.

@ichernev
Copy link
Contributor Author

ichernev commented Mar 6, 2016

Merged in 78bfe90

@Aditya28268
Copy link

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

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

@Aditya28268
Copy link

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

@casvil
Copy link

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/

@ANamelessDeveloper
Copy link

But it's so troublesome.

@Sergio1C
Copy link

Sergio1C commented Feb 1, 2019

But it's so troublesome.

You mean about this warning at console?
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 See http://momentjs.com/guides/#/warnings/define-locale/ for more info.

@keyvan21904
Copy link

i dont know set define & update local for persian!
please help me

Copy link

@KengSSK KengSSK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to the system

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

Successfully merging this pull request may close these issues.

9 participants