Skip to content

i18n: Support array of string values in JavaScript implementation#6328

Merged
aduth merged 5 commits intomainfrom
aduth-i18n-non-string-entry
May 11, 2022
Merged

i18n: Support array of string values in JavaScript implementation#6328
aduth merged 5 commits intomainfrom
aduth-i18n-non-string-entry

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented May 10, 2022

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 t function 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.

aduth added 3 commits May 10, 2022 15:04
**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
@aduth aduth requested a review from nprimak May 10, 2022 19:58
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

LGTM

aduth and others added 2 commits May 10, 2022 16:34
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>

context('with an array of the key', () => {
it('returns array of strings', () => {
const list = t(['list']).map((value) => value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@nprimak nprimak left a comment

Choose a reason for hiding this comment

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

Appreciate you adding the README!

@aduth aduth merged commit 4fcdd08 into main May 11, 2022
@aduth aduth deleted the aduth-i18n-non-string-entry branch May 11, 2022 12:19
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants