Polaris-react: DatePicker (translate/locale)

Created on 19 Oct 2018  路  7Comments  路  Source: Shopify/polaris-react

Hi guys, fine?

I'm using Datepicker component however need translate months and days for my application.

I read about internationalization, but this component uses the properties:

DatePicker

  • nextMonth
  • previousMonth
  • today

How could I solve my question? Could someone help me?

馃寪 International 馃悰Bug

Most helpful comment

I'm going to work on a PR and see where it gets me :)

All 7 comments

Hi @joohncruz 馃憢 Currently, we expose the weekStartsOn prop that allows you to change the first day of the week, since different countries have different calendars. The rest is handled by the browser locale settings. Is there a specific implementation you're trying to achieve? Or a use case where browser locale wouldn't be enough?

Hey @joohncruz, sorry for the delay--you definitely found a bug, thank you 馃檹!

I've been playing around with this today and there's definitely a bug here. The month and day abbreviation strings are in English regardless of what browser language/locale is because we're using utility methods and types from Shopify/javascript-utilities that have hardcoded string enums.

For example, I changed my language to Japanese in the admin, but the DatePicker doesn't translate because these strings are hardcoded.

2019-01-08 4 00 52

I noticed while digging around the DatePicker code that the Month subcomponent has the props weekdayName and monthName. The DatePicker doesn't pass these to the Month and the Month doesn't do anything with them even if they were set. I'm thinking this was an oversight when the component was first built 馃. We definitely need to have props for weekday names and abbreviations along with month names so the translations set to the AppProvider i18n prop can replace the english strings in this component.

Hi! The Analytics Team is also impacted by this as we'd like to have our date pickers fully internationalised, including the calendars that come from Polaris.

My initial thought was to pass through a locale prop and use Intl.DateTimeFormat to format the dates in the required locale. That way we won't need to handle individual translations of every single month / day / year etc.

screen shot 2019-01-14 at 11 00 23 am

Also, happy to contribute on this, or pair, or whatever is necessary :)

I'm going to work on a PR and see where it gets me :)

Thanks @joshuajay!!!

The fix shipped in #1005 will be available in the 3.7.2 release.

Was this page helpful?
0 / 5 - 0 ratings