EuiContext & I18n#1404
Conversation
|
Know this is early but this method looks good to me. It's still pretty readible. Most complicated text I can think of EUI is in the |
|
This looks good from an initial look over. I'm wondering about translations that contain values, for example EuiFilePicker. What does an |
|
@pugnascotia good thinking How about instead of passing the explicit mappings (
This would allow underlying components to rely on the browser built-in The alternative would be to have those translation functions be passed into EUI's context - |
|
Using standard language tags and formalizing the locale as a prop makes sense here, I think. |
|
@pugnascotia @thompsongl I've updated the PR & description and added an |
29e3702 to
792185d
Compare
792185d to
362af8b
Compare
Designer perspective...so do with what you will "Context"Without knowing that behind-the-scenes it uses React context, I wouldn't think of "I18n"I'd still prefix with DocsYou did so well explaining it in the PR summary, can you add more to the actual documentation page? Component exampleCan you update one component that had hard-coded text to use this so we can see an example of how to write them moving forward? |
|
Thanks!
You'll probably never need to know about
👍
Definitely - this was only meant to showcase the API, a full docs page for the i18n components is coming!
👍 |
|
I've added the Eui prefix to the component names and updated |
| onClick={this.onButtonClick} | ||
| > | ||
| {`Rows per page: ${itemsPerPage}`} | ||
| <EuiI18n token="pagination.rowsPerPage" default="Rows per page"/>: {itemsPerPage} |
There was a problem hiding this comment.
Where does this pagination token reside?
There was a problem hiding this comment.
Currently, it does not (nor would EUI define it elsewhere). It would be the key for a translation passed in from e.g. Kibana. The I18n component takes the token and looks it up in the translation map, if it doesn't exist then the default value is used. There will be tooling built to ensure validity of tokens and to track changes (Cloud has a similar setup).
There was a problem hiding this comment.
Yeah so this is where I get confused. So then consumers need to create exactly a
const pagination = {
rowsPerPage = "Rows per page"
}
?
And then how do the pass it to the component.
Ack, I'm sorry these are probably some very basic questions, but I've never dealt with localization before.
There was a problem hiding this comment.
Totally valid questions! This is where EuiContext comes in - context in React is a value that is invisibly passed down to components; those components can either ignore it or opt into receiving the value in addition to their props. This allows translations (context) to be set at a top level and then EUI components simply subscribe to it through EuiI18n. If that context is missing, it will fallback to the default prop.
This means Kibana, Cloud, etc would need to collate the EUI-related translations into a map of {token: copy} and pass it to EuiContext at a high-level in their application (generally these things wrap even the top-most DOM node in a React app). This is the mechanism used by react-router to inform components what page they're on, or redux to invisibly pass state down to subscribing components.
There was a problem hiding this comment.
Maybe a zoom walkthrough next week?
There was a problem hiding this comment.
But I"m not a blocker, just trying to understand
|
I sort-of feel like if you're going to allow |
|
I've collated the occurrences of hard-coded text inside JSX, and potential text locations in JSX expressions & attributes (not an exhaustive list of all possible locations, but the normal places to look) - https://gist.github.com/chandlerprall/5e0f9ceca7e89abc11e1b1d99ac89fca @pugnascotia I'm not sure how much benefit that provides, there are very, very few places in EUI where that kind of interpolation of values would be beneficial. Looking through the places we have hard coded values, there's less than 5 places I see where we even co-locate values, and even then it isn't mixed together like |
|
jenkins test this |
|
@chandlerprall let's just proceed with your design, we'll soon discover if it needs refining when we wire it into Cloud. |
|
@snide @cchaos @ryankeairns @pugnascotia this is ready for a final review Next steps are to find hard coded text and replace with |
snide
left a comment
There was a problem hiding this comment.
We did a walkthru with the designers on this yesterday and I think it works. We can adjust as we move forward into the tokenization, but I think the core concepts work for what we need.
This reverts commit 57d4433.
Summary
Opening this for API review.
from #738
Adds internationalization support via React context.
src-docs/src/views/context/context.js contains the context & i18n usage examples:
EuiContext
EuiContextis used to provide a token->translation mapping and a number formatter for EUI components to use.I18n
I18ncomponent uses the provided token mapping or falls back to the provided default (english) value. I went withI18noverEuiI18nfor readability and to partially infer it shouldn't be used outside of EUI. Not tied to this opinion and could be easily persuaded otherwise.I18n supports three use cases:
supported value types
The tokens can be mapped to any valid ReactChild - i.e. string, number, or JSX - both in the defaults or in the provided mapping.
proposal for token names
I see two options:
EuiComboBox.placeholdercombobox.placeholderI prefer the second way as it creates less turbulence in token names if a token usage moves, e.g. moving the placeholder lookup from EuiComboBox into EuiComboBoxInput
I18nNumber
I18nNumbercomponent uses the providedformatNumberfunction and supports the same three use cases asI18n.Checklist