[wp-trac] [WordPress Trac] #51142: Invalid Moment.js locale from get_user_locale()
WordPress Trac
noreply at wordpress.org
Wed Mar 1 06:03:49 UTC 2023
#51142: Invalid Moment.js locale from get_user_locale()
----------------------------------------+-----------------------------
Reporter: slightlyfaulty | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: External Libraries | Version: 5.0
Severity: normal | Resolution:
Keywords: has-patch needs-unit-tests | Focuses: javascript
----------------------------------------+-----------------------------
Changes (by mukesh27):
* keywords: has-patch => has-patch needs-unit-tests
* milestone: 6.2 => Future Release
Old description:
> `get_user_locale()` returns a locale in the format `en_US`, which is
> passed directly to Moment.js, e.g. `moment.updateLocale( 'en_US', {...}
> )`.
>
> Since Moment.js doesn't actually support two-part locales, this causes
> some issues. For example, `moment().format( 'Do' )` returns `25` where it
> should return `25th`. This is because the local *ordinal* is lost as a
> result of setting an undefined locale.
>
> The locale should either be passed in a format that Moment.js
> understands, such as `en`, or `moment.defineLocale( 'en_US', {
> parentLocale: 'en' } )` should be called before `moment.updateLocale(
> 'en_US', {...} )`. AFAIK these are equivalent.
>
> You can see the issue reproduced here:
> https://codepen.io/slightlyfaulty/pen/WNwpMmG
>
> Of course, swapping out old dusty Moment.js for its super modern and
> popular drop-in replacement [https://day.js.org/ Day.js] is also an
> option 😎
New description:
`get_user_locale()` returns a locale in the format `en_US`, which is
passed directly to Moment.js, e.g. `moment.updateLocale( 'en_US', {...}
)`.
Since Moment.js doesn't actually support two-part locales, this causes
some issues. For example, `moment().format( 'Do' )` returns `25` where it
should return `25th`. This is because the local *ordinal* is lost as a
result of setting an undefined locale.
The locale should either be passed in a format that Moment.js understands,
such as `en`, or `moment.defineLocale( 'en_US', { parentLocale: 'en' } )`
should be called before `moment.updateLocale( 'en_US', {...} )`. AFAIK
these are equivalent.
You can see the issue reproduced here:
https://codepen.io/slightlyfaulty/pen/WNwpMmG
Of course, swapping out old dusty Moment.js for its super modern and
popular drop-in replacement [https://day.js.org/ Day.js] is also an option
--
Comment:
This ticket was discussed during the bug scrub.
As feedback on the PR that needs to address, I think this one is `Future
Release` consideration.
If any committer believes it is ready for commit, please move it back to
the `6.2` milestone.
Additional props: @costdev
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51142#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list