[i18n] Remove i18n token skipping from EUI pluralization defString functions#129144
[i18n] Remove i18n token skipping from EUI pluralization defString functions#129144cee-chen merged 3 commits intoelastic:mainfrom
Conversation
…ana output + add comments/catches for possible future function cases that aren't pluralization
- caught by new unit tests. hooray!
| 'euiSelectable.searchResults': ({ resultsLength }: EuiValues) => | ||
| i18n.translate('core.euiSelectable.searchResults', { | ||
| defaultMessage: '{resultsLength, plural, one {# result} other {# results}}', | ||
| defaultMessage: '{resultsLength, plural, one {# result} other {# results}} available', |
There was a problem hiding this comment.
The new tests caught this default message mistake from a few upgrades ago. Hooray! :)
| throw new Error( | ||
| `We currently only have logic written for EUI pluralization def functions. | ||
| This is a new type of def function that will need custom logic written for it.` | ||
| ); |
There was a problem hiding this comment.
I can't imagine when EUI will ever add function interpolation that isn't for pluralization (see #110132 (comment) to confirm), but if we ever do, I thought it would be prudent to leave this thrown error in for us so that whoever is upgrading the EUI version catches it
| // pluralization). To check EUI's pluralization against Kibana's pluralization, we | ||
| // need to eval the defString and then actually i18n.translate & compare the 2 outputs | ||
| const defFunction = eval(defString); // eslint-disable-line no-eval | ||
| const defFunctionArg = normalizedDefString.split('({ ')[1].split('})')[0]; // TODO: All EUI pluralization fns currently only pass 1 arg. If this changes in the future and 2 args are passed, we'll need to do some extra splitting by ',' |
There was a problem hiding this comment.
Just want to highlight this TODO - I'm not sure when we would ever pass multiple args into an EUI pluralization fn, but if we ever do in the future this logic will need to be reworked because all I'm essentially doing here is isolating the text in '({ someVar })' to get a single variable name
| const VALUES_REGEXP = /\{\w+\}/; | ||
|
|
||
| describe('@elastic/eui i18n tokens', () => { | ||
| const i18nTranslateActual = jest.requireActual('@kbn/i18n').i18n.translate; |
There was a problem hiding this comment.
I wanted this to actually compare final string outputs to each other as I didn't think it was as useful / readable to try and compare the EUI output to some contrived pre-pluralization Kibana version.
afharo
left a comment
There was a problem hiding this comment.
This is great! Thank you for doing this! 🧡 LGTM!
💚 Build SucceededMetrics [docs]Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Bamieh
left a comment
There was a problem hiding this comment.
LGTM. Thank you this is very valuable to have in Kibana after the date picker changes
|
Thanks y'all! |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Summary
This PR handles the pluralization functions in EUI's i18n tokens (see #128825 (comment)). I was hoping to open this PR in after #128825 merged but security tests are being flakey so I'm just going to open this now and rebase later. I did run these tests against all the new EuiSuperDatePicker tokens and can confirm they pass/work as expected.
This PR closes #110132 by correctly checking that the output of EUI's function defStrings output the same strings as i18n's pluralization handling. This requires:
evaling EUI's passed function stringsi18n.translateutil to get final outputExample:
Checklist