Skip to content
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

Guideline for i18n engine #20620

Merged
merged 10 commits into from
Aug 9, 2018

Conversation

maryia-lapata
Copy link
Contributor

@maryia-lapata maryia-lapata commented Jul 10, 2018

It's a guideline for using @kbn/i18n module.
#20074

@maryia-lapata maryia-lapata added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Project:i18n labels Jul 10, 2018
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@epixa epixa removed their request for review July 16, 2018 20:21
@elasticmachine
Copy link
Contributor

💔 Build Failed

@yankouskia
Copy link

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@yankouskia
Copy link

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@yankouskia yankouskia requested review from spalger and removed request for yankouskia July 31, 2018 10:42
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc is really helpful, thanks for putting it together! I put a couple note inline, but some of my comments apply more globally so I figured I would list them here than repeating them over and over inline.

  • I think we should be consistent with the "message ids" name. In some places we say "message ids", in others "The IDs (names) chosen for message keys", and sometimes "key ID". Since we're using a <FormattedMessage /> component with an id prop, I think "message id" is the most logical choice.

  • Would you mind replacing all of the “” (fancy quotes) with simple quote marks "?

  • Nit: Inline code snippets only need two backtick (`) in special cases, would you mind converting the unnecessary double-backticks to singles?

  • Optional Nit: In several places inline code snippets and quotes are mixed. I think most cases should be either one or the other.

  • Question: Is it too late to discuss the format for complex messages? What if instead of:

    kbn.management.editIndexPattern.scripted.deprecationLangLabel.deprecationLangDetail
    kbn.management.editIndexPattern.scripted.deprecationLangLabel.painlessLink
    

    we did something like:

    kbn.management.editIndexPattern.scripted.deprecationLangLabel
    kbn.management.editIndexPattern.scripted.deprecationLangLabel.painlessLink
    

    This structure is a little less redundant and I think it indicates that the the deprecationLangLabel message is complex, and the painlessLink message goes within it.

This phrase contains a variable, which represents languages list, and a link (``Painless``). For such cases we divide the message into two parts: the main message, which contains placeholders, and additional message, which represents inner message.

It is used the following id naming structure:
1) the main message id has the type on the second-to-last position, thereby identifying a divided phrase, and the last segment ends with ``Detail``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure what second-to-last is referring to here.


After translation we get the following structure:
```js
<FormattedMessage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm super excited by this 😄


Each message id should end with a type of the message. For example:

- for header:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section would be more effective if we just listed the message ids and the types. Showing full examples is a little out of scope for what this section is trying to document and makes the actual content a little harder to spot. I think a table presents the information quite nicely:

type example message id
header kbn.management.createIndexPatternHeader
label kbn.management.createIndexPatternLabel
button kbn.management.editIndexPattern.scripted.addFieldButton
drop down kbn.management.editIndexPattern.fields.allTypesDropDown
placeholder kbn.management.createIndexPattern.stepTime.options.patternPlaceholder
aria-label attribute kbn.management.editIndexPattern.removeAria
tooltip kbn.management.editIndexPattern.removeTooltip
error message kbn.management.createIndexPattern.step.invalidCharactersErrorMessage
toggleSwitch kbn.management.createIndexPattern.includeSystemIndicesToggleSwitch

i18n-values="{ conflictFieldsLength: conflictFields.length }"></span>
```

In case when `conflictFieldsLength` has value 1, the result string will be `"A field is defined as several types (string, integer, etc) across the indices that match this pattern."`. In case when `conflictFieldsLength` has value 2 or more, the result string - `"2 fields are defined as several types (string, integer, etc) across the indices that match this pattern."`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case when conflictFieldsLength has value 1

How about

When `conflictFieldsLength` equals 1

or

In cases where the `conflictFieldsLength` has a value of 1

Same for "In case when conflictFieldsLength has value 2"


### Unit tests

Additional adjustments in unit tests are needed only for those components where `injectI18n` component is used. Due to `injectI18n` wraps the target component and passes `intl` via `props`, in tests it is requires to render the target component with `intl` object. That required the rendering the target component using `shallowWithIntl` function from `'test_utils/enzyme_helpers'`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional adjustments in unit tests are needed only for those components where injectI18n component is used. Due to injectI18n wraps the target component and passes intl via props, in tests it is requires to render the target component with intl object. That required the rendering the target component using shallowWithIntl function from 'test_utils/enzyme_helpers'.

I think this reads better as:

When testing React component that use the injectI18n higher-order component, use the shallowWithIntl helper function defined in test_utils/enzyme_helpers to render the component. This will shallow render the component with Enzyme and inject the necessary context and props to use the intl mock defined in test_utils/mocks/intl.


Do you think we should describe what people should do when they want full rendering rather than shallow rendering?

yankouskia added 2 commits August 2, 2018 14:28
…for js strings, fix description for testing, use uniq "message id" name
@yankouskia
Copy link

@spalger thank you for such detailed review!
Regarding points:

  • Absolutely agree, fixed everywhere (message id)

  • Changed everywhere, where possible, but left code examples in accordance to our code style (quote marks)?

  • Removed double back tick

Optional Nit: In several places inline code snippets and quotes are mixed. I think most cases should be either one or the other.

  • Maybe I did not understand this, could you please clarify a little? Or give me an example?

  • Regarding naming convention, that's a good idea to highlight complex part, but I think it's not a scope of this PR, but we could create issue and discuss it with other devs and translate vendors if it is suitable for them too. What do you think?

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@yankouskia
Copy link

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed


```js
<p>
The following deprecated languages are in use: {deprecatedLangsInUse.join(', ')}. Support for these languages will be removed in the next major version of Kibana and Elasticsearch. Convert you scripted fields to <EuiLink href={painlessDocLink}>Painless</EuiLink> to avoid any problems.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misspelling: Convert your scripted fields

This phrase contains a variable, which represents languages list, and a link (`Painless`). For such cases we divide the message into two parts: the main message, which contains placeholders, and additional message, which represents inner message.

It is used the following message id naming structure:
1) the main message id has the type on the penultimate position, thereby identifying a divided phrase, and the last segment ends with `Detail`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace: extra space before Detail


```js
{
'kbn.management.editIndexPattern.scripted.deprecationLangLabel.deprecationLangDetail': 'The following deprecated languages are in use: {deprecatedLangsInUse}. Support for these languages will be removed in the next major version of Kibana and Elasticsearch. Convert you scripted fields to {link} to avoid any problems.'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misspelling: your

'kbn.management.editIndexPattern.scripted.table.nameDescription'
```

- For complex messagges, that is divided into several parts, use the folllowing approach:
Copy link

@rhoboat rhoboat Aug 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar: that are divided into several parts
misspelling: messages, following

- the main message id should have the type on the penultimate position, thereby identifying a divided phrase, and the last segment should end with `Detail`,
- the inner message id should have the type on the penultimate position and the name of the variable from the placeholder in the main message as the last segment that ends with its own type.

For example before the translation there was a message:
Copy link

@rhoboat rhoboat Aug 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar: For example , before (comma reads better)


```js
<strong>Success!</strong>
Your index pattern matches <strong>{exactMatchedIndices.length} {exactMatchedIndices.length > 1 ? 'indices' : 'index'}</strong>.
Copy link

@rhoboat rhoboat Aug 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this ternary is wrong for english. plural is used for everything but the number 1. so it should be {exactMatchedIndices.length === 1 ? 'index' : 'indices'}


`The following dialogue box indicates progress. You can close it and the process will continue to run in the background.`

If this sentence is separated it’s possible that the context of the `'it'` in `'close it'` will be lost.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a better word to use here than "sentence" to describe a group. How about paragraph? Or "sentence or group of sentences"? Since the example there is actually two sentences.

Copy link

@rhoboat rhoboat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nits. Curious what you think, and then I can give another pass through

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@yankouskia
Copy link

@archanid @spalger could you please take a look on updated version?

@spalger
Copy link
Contributor

spalger commented Aug 7, 2018

@yankouskia

Optional Nit: In several places inline code snippets and quotes are mixed. I think most cases should be either one or the other.

Maybe I did not understand this, could you please clarify a little? Or give me an example?

I'm referring to things like "`2 indices`" and `"A field is defined as several types (string, integer, etc) across the indices that match this pattern."`. I highlighted it as more optional than the other nits because it's kind of a grey area, but I think both of those cases would be served just fine with double quotes and the inline-code formatting is just a little distracting, especially when the quotes are on the outside of the code snippet.

I think there's a totally legit argument to be made that comments like:

the result string "2 indices"

are identifying a code snippet of a string, as described, so mixing the quotes and code snippet works, but the actual comment is:

the result string - "2 indices"

where the quotes are on the outside of the code snippet and the - is used to create additional visual separation, both of which could be removed if you ask me.

That said, I'm being SUPER nit-picky with this one 😝

Copy link

@rhoboat rhoboat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this!

@yankouskia yankouskia merged commit 474714a into elastic:master Aug 9, 2018
@yankouskia yankouskia deleted the i18n-engine-guideline branch August 9, 2018 08:38
pavel06081991 pushed a commit to pavel06081991/kibana that referenced this pull request Aug 17, 2018
* Add Guideline for i18n engine

* Update Guideline according to changes in i18n engine.

* Update examples in Guideline

* typo

* improve i18n guideline: add table for better view, use single quotes for js strings, fix description for testing, use uniq "message id" name

* fix readme description for guideline

Co-authored-by: maryia-lapata "mary.lopato@gmail.com"
yankouskia pushed a commit that referenced this pull request Aug 17, 2018
* Add Guideline for i18n engine

* Update Guideline according to changes in i18n engine.

* Update examples in Guideline

* typo

* improve i18n guideline: add table for better view, use single quotes for js strings, fix description for testing, use uniq "message id" name

* fix readme description for guideline

Co-authored-by: maryia-lapata "mary.lopato@gmail.com"
@LeanidShutau
Copy link
Contributor

6.x/6.5: d7b1802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Project:i18n Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v6.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants