mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [Sustainable Kibana Architecture: Move modules owned by `@elastic/kibana-core` (#201653)](https://github.com/elastic/kibana/pull/201653) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Gerard Soldevila","email":"gerard.soldevila@elastic.co"},"sourceCommit":{"committedDate":"2025-01-04T18:47:24Z","message":"Sustainable Kibana Architecture: Move modules owned by `@elastic/kibana-core` (#201653)\n\n## Summary\n\nStart relocating Kibana modules (packages and plugins) to the new folder\nstructure, according to the _Kibana Sustainable Architecture_\ninitiative.\n#### 16 plugin(s) are going to be relocated:\n\n| Id | Target folder |\n| -- | ------------- |\n| `@kbn/cloud-chat-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_chat` |\n| `@kbn/cloud-experiments-plugin` |\n`x-pack/platform/plugins/shared/cloud_integrations/cloud_experiments` |\n| `@kbn/cloud-full-story-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_full_story` |\n| `@kbn/cloud-links-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_links` |\n| `@kbn/cloud-plugin` | `x-pack/platform/plugins/shared/cloud` |\n| `@kbn/features-plugin` | `x-pack/platform/plugins/shared/features` |\n| `@kbn/ftr-apis-plugin` | `src/platform/plugins/private/ftr_apis` |\n| `@kbn/kibana-usage-collection-plugin` |\n`src/platform/plugins/private/kibana_usage_collection` |\n| `@kbn/licensing-plugin` | `x-pack/platform/plugins/shared/licensing` |\n| `@kbn/newsfeed-plugin` | `src/platform/plugins/shared/newsfeed` |\n| `@kbn/saved-objects-management-plugin` |\n`src/platform/plugins/shared/saved_objects_management` |\n| `@kbn/telemetry-collection-manager-plugin` |\n`src/platform/plugins/shared/telemetry_collection_manager` |\n| `@kbn/telemetry-collection-xpack-plugin` |\n`x-pack/platform/plugins/private/telemetry_collection_xpack` |\n| `@kbn/telemetry-management-section-plugin` |\n`src/platform/plugins/shared/telemetry_management_section` |\n| `@kbn/telemetry-plugin` | `src/platform/plugins/shared/telemetry` |\n| `@kbn/usage-collection-plugin` |\n`src/platform/plugins/shared/usage_collection` |\n\n#### 22 package(s) are going to be relocated:\n\n| Id | Target folder |\n| -- | ------------- |\n| `@kbn/analytics` | `src/platform/packages/shared/kbn-analytics` |\n| `@kbn/analytics-collection-utils` |\n`src/platform/packages/private/analytics/utils/analytics_collection_utils`\n|\n| `@kbn/apm-config-loader` |\n`src/platform/packages/private/kbn-apm-config-loader` |\n| `@kbn/cloud` | `src/platform/packages/shared/cloud` |\n| `@kbn/config` | `src/platform/packages/shared/kbn-config` |\n| `@kbn/config-mocks` | `src/platform/packages/private/kbn-config-mocks`\n|\n| `@kbn/config-schema` |\n`src/platform/packages/shared/kbn-config-schema` |\n| `@kbn/crypto-browser` |\n`src/platform/packages/shared/kbn-crypto-browser` |\n| `@kbn/ebt-tools` | `src/platform/packages/shared/kbn-ebt-tools` |\n| `@kbn/es-errors` | `src/platform/packages/shared/kbn-es-errors` |\n| `@kbn/es-types` | `src/platform/packages/shared/kbn-es-types` |\n| `@kbn/hapi-mocks` | `src/platform/packages/private/kbn-hapi-mocks` |\n| `@kbn/health-gateway-server` |\n`src/platform/packages/private/kbn-health-gateway-server` |\n| `@kbn/i18n` | `src/platform/packages/shared/kbn-i18n` |\n| `@kbn/i18n-react` | `src/platform/packages/shared/kbn-i18n-react` |\n| `@kbn/logging` | `src/platform/packages/shared/kbn-logging` |\n| `@kbn/logging-mocks` |\n`src/platform/packages/shared/kbn-logging-mocks` |\n| `@kbn/router-to-openapispec` |\n`src/platform/packages/shared/kbn-router-to-openapispec` |\n| `@kbn/server-http-tools` |\n`src/platform/packages/shared/kbn-server-http-tools` |\n| `@kbn/std` | `src/platform/packages/shared/kbn-std` |\n| `@kbn/utility-types` |\n`src/platform/packages/shared/kbn-utility-types` |\n| `@kbn/zod` | `src/platform/packages/shared/kbn-zod` |\n\n---------\n\nCo-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"6049493e4a2372ea22986b231ad2bd59584fe9b8","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","plugin groups"],"number":201653,"url":"https://github.com/elastic/kibana/pull/201653","mergeCommit":{"message":"Sustainable Kibana Architecture: Move modules owned by `@elastic/kibana-core` (#201653)\n\n## Summary\n\nStart relocating Kibana modules (packages and plugins) to the new folder\nstructure, according to the _Kibana Sustainable Architecture_\ninitiative.\n#### 16 plugin(s) are going to be relocated:\n\n| Id | Target folder |\n| -- | ------------- |\n| `@kbn/cloud-chat-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_chat` |\n| `@kbn/cloud-experiments-plugin` |\n`x-pack/platform/plugins/shared/cloud_integrations/cloud_experiments` |\n| `@kbn/cloud-full-story-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_full_story` |\n| `@kbn/cloud-links-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_links` |\n| `@kbn/cloud-plugin` | `x-pack/platform/plugins/shared/cloud` |\n| `@kbn/features-plugin` | `x-pack/platform/plugins/shared/features` |\n| `@kbn/ftr-apis-plugin` | `src/platform/plugins/private/ftr_apis` |\n| `@kbn/kibana-usage-collection-plugin` |\n`src/platform/plugins/private/kibana_usage_collection` |\n| `@kbn/licensing-plugin` | `x-pack/platform/plugins/shared/licensing` |\n| `@kbn/newsfeed-plugin` | `src/platform/plugins/shared/newsfeed` |\n| `@kbn/saved-objects-management-plugin` |\n`src/platform/plugins/shared/saved_objects_management` |\n| `@kbn/telemetry-collection-manager-plugin` |\n`src/platform/plugins/shared/telemetry_collection_manager` |\n| `@kbn/telemetry-collection-xpack-plugin` |\n`x-pack/platform/plugins/private/telemetry_collection_xpack` |\n| `@kbn/telemetry-management-section-plugin` |\n`src/platform/plugins/shared/telemetry_management_section` |\n| `@kbn/telemetry-plugin` | `src/platform/plugins/shared/telemetry` |\n| `@kbn/usage-collection-plugin` |\n`src/platform/plugins/shared/usage_collection` |\n\n#### 22 package(s) are going to be relocated:\n\n| Id | Target folder |\n| -- | ------------- |\n| `@kbn/analytics` | `src/platform/packages/shared/kbn-analytics` |\n| `@kbn/analytics-collection-utils` |\n`src/platform/packages/private/analytics/utils/analytics_collection_utils`\n|\n| `@kbn/apm-config-loader` |\n`src/platform/packages/private/kbn-apm-config-loader` |\n| `@kbn/cloud` | `src/platform/packages/shared/cloud` |\n| `@kbn/config` | `src/platform/packages/shared/kbn-config` |\n| `@kbn/config-mocks` | `src/platform/packages/private/kbn-config-mocks`\n|\n| `@kbn/config-schema` |\n`src/platform/packages/shared/kbn-config-schema` |\n| `@kbn/crypto-browser` |\n`src/platform/packages/shared/kbn-crypto-browser` |\n| `@kbn/ebt-tools` | `src/platform/packages/shared/kbn-ebt-tools` |\n| `@kbn/es-errors` | `src/platform/packages/shared/kbn-es-errors` |\n| `@kbn/es-types` | `src/platform/packages/shared/kbn-es-types` |\n| `@kbn/hapi-mocks` | `src/platform/packages/private/kbn-hapi-mocks` |\n| `@kbn/health-gateway-server` |\n`src/platform/packages/private/kbn-health-gateway-server` |\n| `@kbn/i18n` | `src/platform/packages/shared/kbn-i18n` |\n| `@kbn/i18n-react` | `src/platform/packages/shared/kbn-i18n-react` |\n| `@kbn/logging` | `src/platform/packages/shared/kbn-logging` |\n| `@kbn/logging-mocks` |\n`src/platform/packages/shared/kbn-logging-mocks` |\n| `@kbn/router-to-openapispec` |\n`src/platform/packages/shared/kbn-router-to-openapispec` |\n| `@kbn/server-http-tools` |\n`src/platform/packages/shared/kbn-server-http-tools` |\n| `@kbn/std` | `src/platform/packages/shared/kbn-std` |\n| `@kbn/utility-types` |\n`src/platform/packages/shared/kbn-utility-types` |\n| `@kbn/zod` | `src/platform/packages/shared/kbn-zod` |\n\n---------\n\nCo-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"6049493e4a2372ea22986b231ad2bd59584fe9b8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201653","number":201653,"mergeCommit":{"message":"Sustainable Kibana Architecture: Move modules owned by `@elastic/kibana-core` (#201653)\n\n## Summary\n\nStart relocating Kibana modules (packages and plugins) to the new folder\nstructure, according to the _Kibana Sustainable Architecture_\ninitiative.\n#### 16 plugin(s) are going to be relocated:\n\n| Id | Target folder |\n| -- | ------------- |\n| `@kbn/cloud-chat-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_chat` |\n| `@kbn/cloud-experiments-plugin` |\n`x-pack/platform/plugins/shared/cloud_integrations/cloud_experiments` |\n| `@kbn/cloud-full-story-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_full_story` |\n| `@kbn/cloud-links-plugin` |\n`x-pack/platform/plugins/private/cloud_integrations/cloud_links` |\n| `@kbn/cloud-plugin` | `x-pack/platform/plugins/shared/cloud` |\n| `@kbn/features-plugin` | `x-pack/platform/plugins/shared/features` |\n| `@kbn/ftr-apis-plugin` | `src/platform/plugins/private/ftr_apis` |\n| `@kbn/kibana-usage-collection-plugin` |\n`src/platform/plugins/private/kibana_usage_collection` |\n| `@kbn/licensing-plugin` | `x-pack/platform/plugins/shared/licensing` |\n| `@kbn/newsfeed-plugin` | `src/platform/plugins/shared/newsfeed` |\n| `@kbn/saved-objects-management-plugin` |\n`src/platform/plugins/shared/saved_objects_management` |\n| `@kbn/telemetry-collection-manager-plugin` |\n`src/platform/plugins/shared/telemetry_collection_manager` |\n| `@kbn/telemetry-collection-xpack-plugin` |\n`x-pack/platform/plugins/private/telemetry_collection_xpack` |\n| `@kbn/telemetry-management-section-plugin` |\n`src/platform/plugins/shared/telemetry_management_section` |\n| `@kbn/telemetry-plugin` | `src/platform/plugins/shared/telemetry` |\n| `@kbn/usage-collection-plugin` |\n`src/platform/plugins/shared/usage_collection` |\n\n#### 22 package(s) are going to be relocated:\n\n| Id | Target folder |\n| -- | ------------- |\n| `@kbn/analytics` | `src/platform/packages/shared/kbn-analytics` |\n| `@kbn/analytics-collection-utils` |\n`src/platform/packages/private/analytics/utils/analytics_collection_utils`\n|\n| `@kbn/apm-config-loader` |\n`src/platform/packages/private/kbn-apm-config-loader` |\n| `@kbn/cloud` | `src/platform/packages/shared/cloud` |\n| `@kbn/config` | `src/platform/packages/shared/kbn-config` |\n| `@kbn/config-mocks` | `src/platform/packages/private/kbn-config-mocks`\n|\n| `@kbn/config-schema` |\n`src/platform/packages/shared/kbn-config-schema` |\n| `@kbn/crypto-browser` |\n`src/platform/packages/shared/kbn-crypto-browser` |\n| `@kbn/ebt-tools` | `src/platform/packages/shared/kbn-ebt-tools` |\n| `@kbn/es-errors` | `src/platform/packages/shared/kbn-es-errors` |\n| `@kbn/es-types` | `src/platform/packages/shared/kbn-es-types` |\n| `@kbn/hapi-mocks` | `src/platform/packages/private/kbn-hapi-mocks` |\n| `@kbn/health-gateway-server` |\n`src/platform/packages/private/kbn-health-gateway-server` |\n| `@kbn/i18n` | `src/platform/packages/shared/kbn-i18n` |\n| `@kbn/i18n-react` | `src/platform/packages/shared/kbn-i18n-react` |\n| `@kbn/logging` | `src/platform/packages/shared/kbn-logging` |\n| `@kbn/logging-mocks` |\n`src/platform/packages/shared/kbn-logging-mocks` |\n| `@kbn/router-to-openapispec` |\n`src/platform/packages/shared/kbn-router-to-openapispec` |\n| `@kbn/server-http-tools` |\n`src/platform/packages/shared/kbn-server-http-tools` |\n| `@kbn/std` | `src/platform/packages/shared/kbn-std` |\n| `@kbn/utility-types` |\n`src/platform/packages/shared/kbn-utility-types` |\n| `@kbn/zod` | `src/platform/packages/shared/kbn-zod` |\n\n---------\n\nCo-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co>\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"6049493e4a2372ea22986b231ad2bd59584fe9b8"}}]}] BACKPORT--> --------- Co-authored-by: Gerard Soldevila <gerard.soldevila@elastic.co>
140 lines
4.4 KiB
Text
140 lines
4.4 KiB
Text
[[external-plugin-localization]]
|
|
== Localization for plugins outside the {kib} repo
|
|
|
|
To introduce localization for your plugin, use our i18n tool to create IDs and default messages. You can then extract these IDs with respective default messages into localization JSON files for {kib} to use when running your plugin.
|
|
|
|
[discrete]
|
|
=== Adding localization to your plugin
|
|
|
|
You must add a `translations` directory at the root of your plugin. This directory will contain the translation files that {kib} uses.
|
|
|
|
["source","shell"]
|
|
-----------
|
|
.
|
|
├── translations
|
|
│ ├── en.json
|
|
│ ├── ja-JP.json
|
|
│ └── zh-CN.json
|
|
└── .i18nrc.json
|
|
-----------
|
|
|
|
|
|
[discrete]
|
|
=== Using {kib} i18n tooling
|
|
To simplify the localization process, {kib} provides tools for the following functions:
|
|
|
|
* Verify all translations have translatable strings and extract default messages from templates
|
|
* Verify translation files and integrate them into {kib}
|
|
|
|
To use {kib} i18n tooling, create a `.i18nrc.json` file with the following configs:
|
|
|
|
* `paths`. The directory from which the i18n translation IDs are extracted.
|
|
* `exclude`. The list of files to exclude while parsing paths.
|
|
* `translations`. The list of translations where JSON localizations are found.
|
|
|
|
["source","json"]
|
|
-----------
|
|
{
|
|
"paths": {
|
|
"myPlugin": "src/ui",
|
|
},
|
|
"exclude": [
|
|
],
|
|
"translations": [
|
|
"translations/zh-CN.json",
|
|
"translations/ja-JP.json"
|
|
]
|
|
}
|
|
-----------
|
|
|
|
An example {kib} `.i18nrc.json` is {kibana-blob}.i18nrc.json[here].
|
|
|
|
Full documentation about i18n tooling is {kibana-blob}src/dev/i18n/README.md[here].
|
|
|
|
[discrete]
|
|
=== Extracting default messages
|
|
To extract the default messages from your plugin, run the following command:
|
|
|
|
["source","shell"]
|
|
-----------
|
|
node scripts/i18n_extract --output-dir ./translations --include-config ../kibana-extra/myPlugin/.i18nrc.json
|
|
-----------
|
|
|
|
This outputs a `en.json` file inside the `translations` directory. To localize other languages, clone the file and translate each string.
|
|
|
|
[discrete]
|
|
=== Checking i18n messages
|
|
|
|
Checking i18n does the following:
|
|
|
|
* Checks all existing labels for violations.
|
|
* Takes translations from `.i18nrc.json` and compares them to the messages extracted and validated.
|
|
** Checks for unused translations. If you remove a label that has a corresponding translation, you must also remove the label from the translations file.
|
|
** Checks for incompatible translations. If you add or remove a new parameter from an existing string, you must also remove the label from the translations file.
|
|
|
|
To check your i18n translations, run the following command:
|
|
|
|
["source","shell"]
|
|
-----------
|
|
node scripts/i18n_check --fix --include-config ../kibana-extra/myPlugin/.i18nrc.json
|
|
-----------
|
|
|
|
|
|
[discrete]
|
|
=== Implementing i18n in the UI
|
|
|
|
{kib} relies on ReactJS and requires localization in different environments (browser and NodeJS).
|
|
The internationalization engine is framework agnostic and consumable in
|
|
all parts of {kib} (ReactJS, and NodeJS).
|
|
|
|
To simplify internationalization in React, an additional abstraction is
|
|
built around the I18n engine using https://github.com/yahoo/react-intl[React-intl] for React.
|
|
|
|
|
|
[discrete]
|
|
==== i18n for vanilla JavaScript
|
|
|
|
["source","js"]
|
|
-----------
|
|
import { i18n } from '@kbn/i18n';
|
|
|
|
export const HELLO_WORLD = i18n.translate('hello.wonderful.world', {
|
|
defaultMessage: 'Greetings, planet Earth!',
|
|
});
|
|
-----------
|
|
|
|
Full details are {kib-repo}tree/main/src/platform/packages/shared/kbn-i18n#vanilla-js[here].
|
|
|
|
[discrete]
|
|
==== i18n for React
|
|
|
|
To localize strings in React, use either `FormattedMessage` or `i18n.translate`.
|
|
|
|
|
|
["source","js"]
|
|
-----------
|
|
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">
|
|
</FormattedMessage>
|
|
</div>
|
|
);
|
|
};
|
|
-----------
|
|
|
|
Full details are {kib-repo}tree/main/src/platform/packages/shared/kbn-i18n#react[here].
|
|
|
|
[discrete]
|
|
=== Resources
|
|
|
|
To learn more about i18n tooling, see {kib-repo}blob/{branch}/src/dev/i18n/README.md[i18n dev tooling].
|
|
|
|
To learn more about implementing i18n in the UI, use the following links:
|
|
|
|
* {kib-repo}blob/{branch}/src/platform/packages/shared/kbn-i18n/README.md[i18n plugin]
|
|
* {kib-repo}blob/{branch}/src/platform/packages/shared/kbn-i18n/GUIDELINE.md[i18n guidelines]
|