docs/extend/tutorials/i18n.md
To internationalize your plugin, use {{kib}}'s i18n tool to create translation IDs and default messages. The tool extracts IDs and default messages into localization JSON files that {{kib}} uses when running your plugin.
Elastic-supported translations ship in the built-in translations plugin, owned by the Localizations team. For the underlying API reference, see @kbn/i18n and the i18n guidelines.
Add a translations directory at the root of your plugin. This directory holds the translation files {{kib}} uses.
.
├── translations
│ ├── en.json
│ ├── ja-JP.json
│ ├── de-DE.json
│ ├── fr-FR.json
│ └── zh-CN.json
└── .i18nrc.json
{{kib}} provides tools to:
To use the tools, create a .i18nrc.json file with:
paths: directories from which i18n translation IDs are extracted.exclude: files to exclude while parsing paths.translations: translation files where JSON localizations live.{
"paths": {
"myPlugin": "src/ui"
},
"exclude": [],
"translations": [
"translations/zh-CN.json",
"translations/fr-FR.json",
"translations/de-DE.json",
"translations/ja-JP.json"
]
}
See an example .i18nrc.json and the full i18n tooling documentation.
Extract the default messages from your plugin:
node scripts/i18n_extract --output-dir ./translations --include-config ../kibana-extra/myPlugin/.i18nrc.json
This outputs an en.json file inside the translations directory. To localize another language, copy the file and translate each string.
The i18n check:
.i18nrc.json and compares them against the extracted and validated messages.
Run the check:
node scripts/i18n_check --fix --include-config ../kibana-extra/myPlugin/.i18nrc.json
{{kib}} uses React and needs localization in both browser and Node.js environments. The internationalization engine is framework-agnostic and usable anywhere in {{kib}}. For React, an additional abstraction is built around the i18n engine using React-intl.
import { i18n } from '@kbn/i18n';
export const HELLO_WORLD = i18n.translate('hello.wonderful.world', {
defaultMessage: 'Greetings, planet Earth!',
});
See the vanilla JS i18n docs.
Localize strings in React with either FormattedMessage or i18n.translate:
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
export const Component = () => {
return (
<div>
{i18n.translate('xpack.someText', { defaultMessage: 'Some text' })}
<FormattedMessage id="xpack.someOtherText" defaultMessage="Some other text" />
</div>
);
};
See the React i18n docs.