Skip to content

[pickers] Stop using utils in locales#14505

Merged
flaviendelangle merged 4 commits intomui:masterfrom
flaviendelangle:stop-using-utils-in-locale
Sep 6, 2024
Merged

[pickers] Stop using utils in locales#14505
flaviendelangle merged 4 commits intomui:masterfrom
flaviendelangle:stop-using-utils-in-locale

Conversation

@flaviendelangle
Copy link
Copy Markdown
Member

@flaviendelangle flaviendelangle commented Sep 5, 2024

Fixes #13768

I need to avoid 2 type of breaking changes

  1. For the people overriding the locale (they must still receive value and utils)
  2. For the people overriding a component that calls this translation (the built-in locale must still work even if they don't pass formattedDate yet)

So I'm handling both the old and the new format in each locale.
This is not clean code, but we can clean it easily during the alpha and the end result will be even better than before this PR.

New DX

In v7

const translations = useTranslations();
// TS will complain since we are not passing the utils, but it will work with any built-in locale
const label = translations.openTimePickerDialogue(value, {} as any, value == null ? null : value.format('MM/DD/YYY'));

In v8

const translations = useTranslations();
// TS will complain since we are not passing the utils, but it will work with any built-in locale
const label = translations.openTimePickerDialogue(value == null ? null : value.format('MM/DD/YYY'));

Follow up

  • In v8 alpha: Remove value and utils params from openDatePickerDialogue, openTimePickerDialogue and clockLabelText

@flaviendelangle flaviendelangle self-assigned this Sep 5, 2024
@flaviendelangle flaviendelangle added scope: pickers Changes related to the date/time pickers. customization: logic Logic customizability. labels Sep 5, 2024
@mui-bot
Copy link
Copy Markdown

mui-bot commented Sep 5, 2024

Localization writing tips ✍️

Seems you are updating localization 🌍 files.

Thank you for contributing to the localization! 🎉 To make your PR perfect, here is a list of elements to check: ✔️

  • Verify if the PR title respects the release format. Here are two examples (depending if you update or add a locale file)

    [l10n] Improve Swedish (sv-SE) locale
    [l10n] Add Danish (da-DK) locale

  • Update the documentation of supported locales by running pnpm l10n
  • Clean files with pnpm prettier.

Deploy preview: https://deploy-preview-14505--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 87b392e

@flaviendelangle flaviendelangle force-pushed the stop-using-utils-in-locale branch 2 times, most recently from 6d4b7ff to 6c5ee15 Compare September 5, 2024 15:23
@flaviendelangle flaviendelangle force-pushed the stop-using-utils-in-locale branch from 6c5ee15 to fcb0c56 Compare September 5, 2024 15:24
Comment thread packages/x-date-pickers/src/locales/utils/pickersLocaleTextApi.ts
@flaviendelangle flaviendelangle force-pushed the stop-using-utils-in-locale branch from d3581a8 to 14115d2 Compare September 6, 2024 06:35
@flaviendelangle flaviendelangle marked this pull request as ready for review September 6, 2024 06:38
@flaviendelangle flaviendelangle requested review from LukasTy, arthurbalduini and kealjones-wk and removed request for kealjones-wk September 6, 2024 06:38
@flaviendelangle flaviendelangle force-pushed the stop-using-utils-in-locale branch from 14115d2 to 87a1495 Compare September 6, 2024 06:46
Copy link
Copy Markdown
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

Thank you for taking care of it! 🙏
The DX looks great. 👍
We are going to clean this up nicely on 8. 👌

Comment thread packages/x-date-pickers/src/DesktopDatePicker/DesktopDatePicker.tsx Outdated
Comment thread packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.tsx Outdated
Comment thread packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.tsx Outdated
Comment thread packages/x-date-pickers/src/MobileDatePicker/MobileDatePicker.tsx Outdated
Comment thread packages/x-date-pickers/src/MobileDateTimePicker/MobileDateTimePicker.tsx Outdated
Comment thread packages/x-date-pickers/src/MobileTimePicker/MobileTimePicker.tsx Outdated
Comment thread packages/x-date-pickers/src/locales/utils/pickersLocaleTextApi.ts
Copy link
Copy Markdown
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

👏 🚀 💯

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

Labels

customization: logic Logic customizability. scope: pickers Changes related to the date/time pickers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pickers] How can I get access to the Pickers Adapter Utils for use with usePickersTranslations?

4 participants