feat: Add displayName to useFormatter#2285
Conversation
|
@roderickhsiao is attempting to deploy a commit to the next-intl Team on Vercel. A member of the Team first needs to authorize it. |
amannn
left a comment
There was a problem hiding this comment.
Hey @roderickhsiao, thanks a lot for this PR—this looks really great!
There's only one API consideration I'd raise, let me know what you think.
|
@amannn thanks for the review, love the work! updated PR. Cheers |
displayName to useFormatter
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Awesome, thanks! One last thing: CI is failing because size budgets for See Can you have a quick look? I think maintainer edits aren't turned on for this PR. |
I got you, one sec |
|
Regarding 597c3e4, I think I'd prefer a sorting in the docs based on how often the APIs are needed (dates and numbers more than display names). Can you revert that part? In code, I'm fine with either sorting. |
|
I'll let you decide, I think its in general the usage is kind of bias (if number is more than dates?) but I also get your point |
|
Yeah, I honestly don't know if date or number formatting is more popular (would guess for dates), but having these come first makes sense IMO. Thanks a lot! |
This reverts commit 597c3e4.
7b3f768 to
98b3e26
Compare
amannn
left a comment
There was a problem hiding this comment.
One minor thing I noticed on a final look
|
Thank you for the patient review :) |
Description
Exposes
Intl.DisplayNamesthrough theuseFormatterhook as a new singulardisplayNameformatter, consistent with existing formatter APIs while matching the underlyingIntl.DisplayNamesnaming.Why
Intl.DisplayNameswas already wired in the internal formatter cache (createIntlFormatters) but was never surfaced viauseFormatter. This PR adds the missing public API and keeps naming/docs aligned.What changed
packages/use-intl/src/core/createFormatter.tsxdisplayName(value, options)anddisplayName(value, format, options?)overloads.formatters.getDisplayNamescache-backed instances.packages/use-intl/src/core/Formats.tsxdisplayName?: Record<string, Intl.DisplayNamesOptions>to global formats.packages/use-intl/src/core/AppConfig.tsxdisplayNameformat-name typing support inFormatNamesaugmentation.packages/use-intl/src/react/useFormatter.test.tsxIntl.DisplayNamesinstance caching.docs/src/pages/docs/usage/display-name.mdx(renamed fromdisplay-names.mdx) with singular API examples.docs/src/pages/docs/usage/_meta.tsxroute key updated todisplay-name.docs/src/pages/docs/usage/configuration.mdxanddocs/src/pages/docs/workflows/typescript.mdxupdated to singular key/API usage.docs/src/pages/docs/environments/runtime-requirements.mdxnow explicitly listsIntl.DisplayNamesand corresponding polyfill entries.Test plan
format.displayName('US', {type: 'region'})-> "United States"format.displayName('en', {type: 'language'})-> "English"format.displayName('USD', {type: 'currency'})-> "US Dollar"format.displayName('US', 'region')withformats.displayName.region = {type: 'region'}Intl.DisplayNamesinstances are cached for equivalent optionsVerification run
pnpm --filter use-intl test -- run src/react/useFormatter.test.tsx(pass)