-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[i18n] Remove i18n token skipping from EUI pluralization defString functions #129144
Conversation
…ana output + add comments/catches for possible future function cases that aren't pluralization
- caught by new unit tests. hooray!
@@ -966,7 +966,7 @@ export const getEuiContextMapping = (): EuiTokensObject => { | |||
), | |||
'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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -17,6 +17,7 @@ import { getEuiContextMapping } from './i18n_eui_mapping'; | |||
const VALUES_REGEXP = /\{\w+\}/; | |||
|
|||
describe('@elastic/eui i18n tokens', () => { | |||
const i18nTranslateActual = jest.requireActual('@kbn/i18n').i18n.translate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
eval
ing EUI's passed function stringsi18n.translate
util to get final outputExample:
Checklist