-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enhance formatMessage
from useTranslation
with direct string support
#4121
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
This was referenced Oct 14, 2024
langz
approved these changes
Oct 14, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
langz
added a commit
that referenced
this pull request
Oct 15, 2024
This PR relies on #4121 as of now. This lets form components consume the internal translations as well as extending the translations with your own strings: ```tsx import { Form } from '@dnb/eufemia/extensions/forms' const myTranslations = { 'en-GB': { Custom: { translation: 'My translation with a {myKey}', }, }, } function MyComponent() { const { Custom, formatMessage } = Form.useTranslation<myTranslations>() // Use it directly const str1 = formatMessage(Custom.translation, { myKey: 'value!', }) // Or use it with a key const str2 = formatMessage('Field.errorRequired', { myKey: 'value!', }) return <>MyComponent</> } <Form.Handler locale="en-GB" translations={myTranslations}> <MyComponent /> </Form.Handler> ``` --------- Co-authored-by: Anders <anderslangseth@gmail.com>
langz
force-pushed
the
feat/get-translation-value
branch
from
October 15, 2024 12:39
8375093
to
8650e21
Compare
tujoworker
pushed a commit
that referenced
this pull request
Oct 18, 2024
## [10.53.0](v10.52.1...v10.53.0) (2024-10-18) ### 🐛 Bug Fixes * **Forms:** keep Iterate.Array in sync with the data context and call onChange when `countPath` changes ([#4147](#4147)) ([095ddaa](095ddaa)) * **Forms:** UI alignments of the ChildrenWithAge block ([#4137](#4137)) ([3db7201](3db7201)) * **Upload:** handle file extensions with case insensitivity ([#4138](#4138)) ([fd9d9ba](fd9d9ba)) ### ✨ Features * add `renderMessage` to useTranslation hook for line-break support ([#4125](#4125)) ([5b07bec](5b07bec)) * **Forms:** add `country` prop to Field.PostalCodeAndCity to support other countries than Norway ([#4109](#4109)) ([5095bea](5095bea)) * **Forms:** add `Form.useTranslation` hook ([#4123](#4123)) ([6f40922](6f40922)), closes [#4121](#4121) * **Forms:** add support for `minItems`/`maxItems` error messages to Field.ArraySelection ([#4120](#4120)) ([29ebe55](29ebe55)) * **Forms:** add support to set a custom `width` to fields and values ([#4142](#4142)) ([07b257f](07b257f)) * **Forms:** add validation to Field.BankAccountNumber ([#4119](#4119)) ([f70ba3d](f70ba3d)) * **Forms:** warn when a field path is declared more than one time ([#4127](#4127)) ([ca15887](ca15887))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for formatting a custom string arguments:
From before,
formatMessage
did support dot-notated keys of an object: