Skip to content

Add zh-CN.json translations and respective compatibility checks via i18n tools#30378

Merged
azasypkin merged 5 commits intoelastic:masterfrom
azasypkin:issue-xxx-improve-i18n-integrate
Feb 11, 2019
Merged

Add zh-CN.json translations and respective compatibility checks via i18n tools#30378
azasypkin merged 5 commits intoelastic:masterfrom
azasypkin:issue-xxx-improve-i18n-integrate

Conversation

@azasypkin
Copy link
Copy Markdown
Contributor

@azasypkin azasypkin commented Feb 7, 2019

Fixes #30143

The only non-dev thing that this PR includes is the file with translations (zh-CN.json), the rest are changes in i18n dev tools that can help us to maintain zh-CN.json in master as compatible to the new changes as possible.

List of notable changes:

  • Removed 177 unused and 4 incompatible labels from zh-CN.json forward-ported from 6.7 branch
  • Renamed former i18n_check to i18n_extract and introduced new i18n_check based on i18n_extract and i18n_integrate
  • Added --ignore-unused, --ignore-missing and --ignore-incompatible options to both i18n_check and i18n_integrate (see docs for more details)
  • Added translations field to .i18nrc.json to know which files exactly we should use in compatibility checks
  • Added --target parameter for i18n_integrate to store all translations inside of a single file to support x-pack/translations (without this option, translations file is split and distributed across plugin folders based on mappings defined in .i18nrc.json)
  • Tried to convert as much i18n tools to TypeScript as was feasible

On CI we'll run (--ignore-missing to not complain about new non-translated labels):

$ node scripts/i18n_check.js  --ignore-missing

The command above will do the following checks:

  1. Check all existing labels for violations like before
  2. Take translations from .i18nrc.json and compare them to the messages extracted and validated at the step above and:
    2.1 Check for unused translations - if developer removed a label which has corresponding translation they will need to remove this label from translations file as well, semi-automatic for now (see below)
    2.2 Check for incompatible translations - if developer, let's say removed or added new parameter to an existing string, they will need to remove this label from translations file.

To fix 2.1 and 2.2 (assuming changes are intentional), one should run the following command:

$ node scripts/i18n_check.js --fix

That is currently expanded into the following command under the hood (simplified):

$ node scripts/i18n_extract [no file is written, just labels are extracted and validated]
$ node scripts/i18n_integrate.js \
   --source x-pack/plugins/translations/translations/zh-CN.json \
   --target x-pack/plugins/translations/translations/zh-CN.json \
   --ignore-missing \
   --ignore-unused \
   --ignore-incompatible

We can tune defaults once we get feedback, let's see.

To integrate files we receive from translators right now, one can use the following command:

$ node scripts/i18n_integrate.js \
   --source /some-path/to/zh-CN.json \
   --target x-pack/plugins/translations/translations/zh-CN.json \
   [--ignore-missing] \
   [--ignore-unused]

The ignore-* options shouldn't be used when integrating into the same revision from which en.json was created otherwise we may miss some errors that were done during translation.

@azasypkin azasypkin added dev Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// Project:i18n v7.0.0 v8.0.0 v6.7.0 labels Feb 7, 2019
@azasypkin azasypkin requested a review from Bamieh February 7, 2019 13:04
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-platform

Comment thread .i18nrc.json
"x-pack/plugins/infra/server/graphql/types.ts",
"x-pack/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts"
],
"translations": [
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note: we need to track these files somewhere for a compatibility checks and automatic fixes.

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@azasypkin azasypkin changed the title Add zh-CN.json translations and respective compatibility via i18n tools Add zh-CN.json translations and respective compatibility checks via i18n tools Feb 8, 2019
Comment thread src/dev/i18n/config.ts Outdated
await readFileAsync(resolve(configPath))
);

for (const [namespace, path] of Object.entries(additionalConfig.paths || [])) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is neater to merge defaults when defining additionalConfig instead of having || statements in the for statements

Comment thread src/dev/i18n/config.ts Outdated

/**
* Filters out custom paths based on the paths defined in config and that are
* known to contain 1i8n strings.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* known to contain 1i8n strings.
* known to contain i18n strings.

const mockMakeDirAsync = jest.fn();
jest.mock('./utils', () => ({
// Jest typings don't define `requireActual` for some reason.
...(jest as any).requireActual('./utils'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(ignore this; just a general note)

Weird it is in the DefinitelyTyped definition, maybe on a newer version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we need to update our jest types at some point (and jest as well).

Comment thread src/dev/i18n/integrate_locale_files.ts Outdated

const missingTranslations = difference(defaultMessagesIds, localizedMessagesIds);
if (!options.ignoreMissing && missingTranslations.length > 0) {
errorMessage += `\n${
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe moving the missingTranslations definition line inside the options.ignoreMissing condition is better to avoid evaluating for nothing?

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@azasypkin
Copy link
Copy Markdown
Contributor Author

6.7: e767f90
7.0: 5c2c116
7.x/7.1: d5fe0ae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported dev Project:i18n Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v6.7.0 v7.0.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[7.0] Introduce Chinese translations

3 participants