Skip to content

i18n: Detect array keys for Webpack string extraction#6359

Merged
aduth merged 4 commits intomainfrom
aduth-i18n-array-keys-extraction
May 19, 2022
Merged

i18n: Detect array keys for Webpack string extraction#6359
aduth merged 4 commits intomainfrom
aduth-i18n-array-keys-extraction

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented May 16, 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.

Related: #6323 (comment)

aduth added 4 commits May 18, 2022 07:58
**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
This previously wasn't able to use array syntax because string extraction wasn't implemented, and now it is
@aduth aduth force-pushed the aduth-i18n-array-keys-extraction branch from 8a01213 to 27c7e1a Compare May 18, 2022 12:01
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

* @type {RegExp}
*/
const TRANSLATE_CALL = /(?:^|[^\w'-])(?:I18n\.)?t\)?\(\s*['"](.+?)['"][,\s)]/g;
const TRANSLATE_CALL = /(?:^|[^\w'-])t\)?\(\[?(['"][a-z\d\s_.,'"]+['"])]?[,\s)]/g;
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope we can continue to use regexes for this and don't have to get into parser/lexer/AST land lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good luck to whoever has to try to interpret this regex in the future! (My future self included) 😅

@aduth aduth merged commit cfee901 into main May 19, 2022
@aduth aduth deleted the aduth-i18n-array-keys-extraction branch May 19, 2022 19:07
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.

2 participants