feat: Added support for default formatters #2018
Closed
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.
Add support for default formatters
This PR introduces automatic default formatter handling for ICU message format placeholders and function-based formatters that don't specify a format.
Changes
Automatic default format injection: Messages with placeholders like
{value, number}are automatically transformed to{value, number, default}before parsing.Function formatter support: The
useFormatterhook andcreateFormatterfunction now apply default formats when no specific format is provided.Generic type support: Works with any ICU message format or function-based fromat type (number, date, time, plural, etc.)
Unified configuration: Both ICU types and function formatters can define default formats in the IntlProvider's formats prop
Implementation
The transformation is handled by a regex pattern
/\{([^,}]+),\s*(\w+)\s*}/gthat:useFormatterandcreateFormattercheck for default format configurations when no explicit format is provided