[wp-trac] [WordPress Trac] #51142: Invalid Moment.js locale from get_user_locale()

WordPress Trac noreply at wordpress.org
Tue Aug 25 22:28:16 UTC 2020


#51142: Invalid Moment.js locale from get_user_locale()
--------------------------------+-----------------------------
 Reporter:  slightlyfaulty      |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  External Libraries  |    Version:  5.5
 Severity:  normal              |   Keywords:
  Focuses:  javascript          |
--------------------------------+-----------------------------
 `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
 😎

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51142>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list