i18n: Support array of string values in JavaScript implementation#6328
Merged
i18n: Support array of string values in JavaScript implementation#6328
Conversation
**Why**: For feature parity with Rails localization, we should be able to retrieve an array of strings from locale data. changelog: Internal, Localization, Improve browser localization to support array of messages
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
aduth
commented
May 10, 2022
|
|
||
| context('with an array of the key', () => { | ||
| it('returns array of strings', () => { | ||
| const list = t(['list']).map((value) => value); |
Contributor
Author
There was a problem hiding this comment.
For posterity, in case it raises eyebrows: The reason for the identity map is mostly to ensure that, when type-checked, TypeScript takes no issue with the fact that the return value would be expected to be an array, as an assurance of the contract that, when given an array of keys, the return value should be an array of messages.
nprimak
approved these changes
May 10, 2022
Contributor
nprimak
left a comment
There was a problem hiding this comment.
Appreciate you adding the README!
Merged
aduth
added a commit
that referenced
this pull request
May 18, 2022
**Why**: In order for array key support implemented in #6328 to appear as translated, the keys must be extracted, which means we need additional support in the Webpack plugin to detect and extract array keys. changelog: Internal, Localization, Improve browser localization to support array of messages
aduth
added a commit
that referenced
this pull request
May 19, 2022
* i18n: Detect array keys for Webpack string extraction **Why**: In order for array key support implemented in #6328 to appear as translated, the keys must be extracted, which means we need additional support in the Webpack plugin to detect and extract array keys. changelog: Internal, Localization, Improve browser localization to support array of messages * Fix lint error * Fix extra transpilation cases with mid-string interpolation * Use array syntax for idv forgot password warnings This previously wasn't able to use array syntax because string extraction wasn't implemented, and now it is
This file contains hidden or 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
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.
Why: For feature parity with Rails localization, we should be able to retrieve an array of strings from locale data.
More context: #6323 (comment)
To improve usability with TypeScript, this implementation assumes that the return type of the
tfunction would only be an array of strings if and only if the key is given as an array, since otherwise the consumer would need to be able to handle a return type of either a string or an array of strings.