i18n: support reusing the same placeholder for ICU #16159
Merged
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.
It can be useful to reuse the same ICU variable names in a i18n string. For example:
source
The above currently ends up with this in our ctc file:
"message": "Your local $ICU_0$ $ICU_1$ needs improvement and is rated the same as $ICU_3$ of real-user {PH1} experiences. However, the field data 75th percentile {PH1} $ICU_2$ is good."
(this is wrong).We already support replacing multiple instances of a ICU variable: https://github.com/GoogleChrome/lighthouse/blob/c79628af9bdaa537a2abd1b34da922e28b81bd98/core/test/scripts/i18n/bake-ctc-to-lhl-test.js#L43C50-L60
But our collect strings step does not currently ever produce a ICU message string that reuses the same variable. For direct ICU (like the above example), it would just leave the
{PH1}
literal as-is for subsequent instances. For the custom format one, it would create a new variable. This PR fixes both of those cases.internal links:
https://localizer.google.com/query/13584722