Repository navigation
Initial go at localizing some components - #1450
Conversation
|
@chandlerprall and I chatted briefly over Slack on this. He's gonna reach out to people on the downstream consumer teams to get feedback (since I'm the least helpful here). There's no need to rush into decisions and we can wait a day before going nuts in the repo. Exciting that even given the syntax questions, we're able to cover so much of the repo so quickly. That's always a good sign :) |
|
So where are we at with |
|
EUI will not be including <EuiI18n
token=""
default="{greeting}, {name}"
values={{ greeting: 'Hello', name: 'Rory' }}
/>This PR is technically ready for review but blocked for merging by elastic/kibana#24707 to add enzyme support for React's new context API. |
|
@pugnascotia this is fully ready for review. The conflicts are around the original I18n revert which is now ready to be re-reverted. |
| const activityLabel = isReadOnly ? 'Interacting' : 'Editing'; | ||
| const activity = isReadOnly | ||
| ? 'interacting with the code' | ||
| : 'editing'; |
There was a problem hiding this comment.
Is this getting localised too? Not obvious that it is.
There was a problem hiding this comment.
No, activityLabel is used in forming the tokens later. However, how I'm using it here breaks the planned static analysis of tokens, I'll refactor.
| When you’re done, press Escape to stop {activity}. | ||
| <EuiI18n | ||
| token={`euiCodeEditor.stop${activityLabel}`} | ||
| default={` When you're done, press Escape to stop ${activity}.`} |
There was a problem hiding this comment.
In case whitespace matters:
| default={` When you're done, press Escape to stop ${activity}.`} | |
| default={`When you're done, press Escape to stop ${activity}.`} |
| <EuiI18n | ||
| token="euiComboBoxOptionsList.createCustomOption" | ||
| default="Hit {key} to add {searchValue} as a custom option" | ||
| values={{ key: <EuiCode>ENTER</EuiCode>, searchValue: <strong>{searchValue}</strong> }} |
There was a problem hiding this comment.
Should ENTER be localised?
There was a problem hiding this comment.
It is still localizable, the consumer can ignore that default value in their formatting:
'euiComboBoxOptionsList.createCustomOption': ({ searchValue }) => {
return i18n.translate(
'common.ui.euiComboBoxOptionsList.createCustomOption',
{
defaultMessage: 'Hit <EuiCode>ENTER</EuiCode> to add {searchValue} as a custom option',
values: { searchValue // forwarded from EUI's call into this function }
}
);
}
Since react-intl allows JSX in the translations, the key value can be ignored and the localized value put directly into the message.
| Use the up and down keys to navigate or escape to close. | ||
| <EuiI18n | ||
| token="euiSuperSelect.screenReaderAnnouncement" | ||
| default={`You are in a form selector of {optionsCount} items and must select a single option. |
There was a problem hiding this comment.
Ooof, not handling item/items? :-P
There was a problem hiding this comment.
Wasn't going to refactor any logic as part of this :-D
| values?: I18nTokenShape<T>['values'] | ||
| ): ReactChild { | ||
| const renderable = (i18nMapping && i18nMapping[token]) || valueDefault; | ||
| if (typeof renderable === 'function') { |
There was a problem hiding this comment.
Personal style choice - since each branch here returns, I'd remove the else nits. No big deal though.
There was a problem hiding this comment.
Updated to remove else blocks.
| appendValueToChildren(child); | ||
| child = {propName: ''}; | ||
| } else if (char === '}') { | ||
| // @ts-ignore |
There was a problem hiding this comment.
Updated code to use a type cast instead of completely ignoring the line to better communicate intent.
Converts a number of text locations to use
EuiI18n.Couple notes:
I updated
EuiI18n's default prop to accept a function which consumes a passed values object and returns the formatted text/element. The other option (as Rory suggested) is have a formatter function be exposed through theEuiContext. This would let the default messages be forwarded directly to e.g.react-intl. I tried bringingreact-intldirectly into EUI to allow defaults to be processed by it for a cleaner API, but it doesn't look like you can get JSX in messages without directly using theirFormattedMessagecomponent. The other way to go instead is to throw awayEuiI18nand usereact-intldirectly in EUI, with the hard dependency it brings - the API surface is largely the same, basically replacing EuiI18n -> FormattedMessage.Thoughts @snide @pugnascotia ?