-
Notifications
You must be signed in to change notification settings - Fork 841
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
Initial go at localizing some components #1450
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. |
@@ -141,11 +142,11 @@ export class EuiCodeEditor extends Component { | |||
filteredCursorStart = cursorStart; | |||
} | |||
|
|||
const activityLabel = isReadOnly ? 'Interacting' : 'Editing'; | |||
const activity = isReadOnly | |||
? 'interacting with the code' | |||
: 'editing'; |
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.
Is this getting localised too? Not obvious that it is.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ENTER
be localised?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooof, not handling item/items? :-P
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to remove else
blocks.
src/components/i18n/i18n_util.tsx
Outdated
appendValueToChildren(child); | ||
child = {propName: ''}; | ||
} else if (char === '}') { | ||
// @ts-ignore |
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.
How come?
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.
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-intl
directly 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 theirFormattedMessage
component. The other way to go instead is to throw awayEuiI18n
and usereact-intl
directly in EUI, with the hard dependency it brings - the API surface is largely the same, basically replacing EuiI18n -> FormattedMessage.Thoughts @snide @pugnascotia ?