mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[I18n] Register translations before plugins init (#26078)
* Register translations before plugins init * Fix i18n engine initialization * Fix translationPath$ RxJS pipeline * Move translations registration to mixin * Fix arrays concatenation * Use prettier * Fix translations relative paths * Use globby instead of glob * Update docs * Move globby to dependencies * Get rid of translation directories config * Update globby patterns * Search only for current locale translation files
This commit is contained in:
parent
9134ad4622
commit
46a8ad4a53
8 changed files with 39 additions and 49 deletions
|
@ -144,6 +144,7 @@
|
|||
"getos": "^3.1.0",
|
||||
"glob": "^7.1.2",
|
||||
"glob-all": "^3.1.0",
|
||||
"globby": "^8.0.1",
|
||||
"good-squeeze": "2.1.0",
|
||||
"h2o2": "^8.1.2",
|
||||
"handlebars": "4.0.5",
|
||||
|
@ -337,7 +338,6 @@
|
|||
"fetch-mock": "^5.13.1",
|
||||
"geckodriver": "1.12.2",
|
||||
"getopts": "2.0.0",
|
||||
"globby": "^8.0.1",
|
||||
"grunt": "1.0.1",
|
||||
"grunt-cli": "^1.2.0",
|
||||
"grunt-contrib-watch": "^1.1.0",
|
||||
|
|
|
@ -33,21 +33,7 @@ For example:
|
|||
src/legacy/core_plugins/kibana/translations/fr.json
|
||||
```
|
||||
|
||||
When a new translation file is added, you have to register this file into
|
||||
`uiExports.translations` array of plugin constructor parameters. For example:
|
||||
```js
|
||||
export default function (kibana) {
|
||||
return new kibana.Plugin({
|
||||
uiExports: {
|
||||
translations: [
|
||||
resolve(__dirname, './translations/fr.json'),
|
||||
],
|
||||
...
|
||||
},
|
||||
...
|
||||
});
|
||||
}
|
||||
```
|
||||
The engine scans `x-pack/plugins/*/translations`, `src/core_plugins/*/translations`, `plugins/*/translations` and `src/ui/translations` folders on initialization, so there is no need to register translation files.
|
||||
|
||||
The engine uses a `config/kibana.yml` file for locale resolution process. If locale is
|
||||
defined via `i18n.locale` option in `config/kibana.yml` then it will be used as a base
|
||||
|
|
|
@ -134,8 +134,6 @@ export default function (kibana) {
|
|||
};
|
||||
},
|
||||
|
||||
translations: [],
|
||||
|
||||
mappings,
|
||||
uiSettingDefaults: getUiSettingDefaults(),
|
||||
},
|
||||
|
|
|
@ -104,7 +104,6 @@ export default function (kibana) {
|
|||
category: ['timelion'],
|
||||
}
|
||||
},
|
||||
translations: [],
|
||||
},
|
||||
init: require('./init.js'),
|
||||
});
|
||||
|
|
|
@ -17,12 +17,45 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { resolve } from 'path';
|
||||
import globby from 'globby';
|
||||
import { i18n, i18nLoader } from '@kbn/i18n';
|
||||
|
||||
import { fromRoot } from '../../utils';
|
||||
|
||||
export async function i18nMixin(kbnServer, server, config) {
|
||||
const { translationPaths = [] } = kbnServer.uiExports;
|
||||
const locale = config.get('i18n.locale');
|
||||
|
||||
const translationsDirs = [fromRoot('src/ui/translations')];
|
||||
|
||||
const groupedEntries = await Promise.all([
|
||||
...config.get('plugins.scanDirs').map(async path => {
|
||||
const entries = await globby(`*/translations/${locale}.json`, {
|
||||
cwd: path,
|
||||
});
|
||||
return entries.map(entry => resolve(path, entry));
|
||||
}),
|
||||
|
||||
...config.get('plugins.paths').map(async path => {
|
||||
const entries = await globby(
|
||||
[`translations/${locale}.json`, `plugins/*/translations/${locale}.json`],
|
||||
{
|
||||
cwd: path,
|
||||
}
|
||||
);
|
||||
return entries.map(entry => resolve(path, entry));
|
||||
}),
|
||||
|
||||
...translationsDirs.map(async path => {
|
||||
const entries = await globby(`${locale}.json`, {
|
||||
cwd: path,
|
||||
});
|
||||
return entries.map(entry => resolve(path, entry));
|
||||
}),
|
||||
]);
|
||||
|
||||
const translationPaths = [].concat(...groupedEntries);
|
||||
|
||||
i18nLoader.registerTranslationFiles(translationPaths);
|
||||
|
||||
const pureTranslations = await i18nLoader.getTranslationsByLocale(locale);
|
||||
|
|
|
@ -75,6 +75,9 @@ export default class KbnServer {
|
|||
// writes pid file
|
||||
pidMixin,
|
||||
|
||||
// scan translations dirs, register locale files, initialize i18n engine and define `server.getUiTranslations`
|
||||
i18nMixin,
|
||||
|
||||
// find plugins and set this.plugins and this.pluginSpecs
|
||||
Plugins.scanMixin,
|
||||
|
||||
|
@ -83,7 +86,6 @@ export default class KbnServer {
|
|||
|
||||
// setup this.uiExports and this.uiBundles
|
||||
uiMixin,
|
||||
i18nMixin,
|
||||
indexPatternsMixin,
|
||||
|
||||
// setup saved object routes
|
||||
|
|
|
@ -61,10 +61,6 @@ export {
|
|||
shareContextMenuExtensions,
|
||||
} from './ui_app_extensions';
|
||||
|
||||
export {
|
||||
translations,
|
||||
} from './ui_i18n';
|
||||
|
||||
export {
|
||||
link,
|
||||
links,
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { flatConcatAtType } from './reduce';
|
||||
import { wrap, alias } from './modify_reduce';
|
||||
|
||||
// paths to translation files
|
||||
export const translations = wrap(alias('translationPaths'), flatConcatAtType);
|
Loading…
Add table
Add a link
Reference in a new issue