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

[I18n] Register translations before plugins init #26078

Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,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",
Expand Down Expand Up @@ -334,7 +335,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",
Expand Down
16 changes: 1 addition & 15 deletions packages/kbn-i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,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
Expand Down
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ export default function (kibana) {
};
},

translations: [],

mappings,
uiSettingDefaults: getUiSettingDefaults(),
},
Expand Down
1 change: 0 additions & 1 deletion src/legacy/core_plugins/timelion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export default function (kibana) {
category: ['timelion'],
}
},
translations: [],
},
init: require('./init.js'),
});
Expand Down
32 changes: 31 additions & 1 deletion src/server/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,42 @@
* 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/*.json', {
cwd: path,
});
return entries.map(entry => resolve(path, entry));
}),

...config.get('plugins.paths').map(async path => {
const entries = await globby('plugins/*/translations/*.json', {
LeanidShutau marked this conversation as resolved.
Show resolved Hide resolved
cwd: path,
});
return entries.map(entry => resolve(path, entry));
}),

...translationsDirs.map(async path => {
const entries = await globby('*.json', {
cwd: path,
});
return entries.map(entry => resolve(path, entry));
}),
]);

const translationPaths = [].concat(...groupedEntries);

i18nLoader.registerTranslationFiles(translationPaths);

const pureTranslations = await i18nLoader.getTranslationsByLocale(locale);
Expand Down
4 changes: 3 additions & 1 deletion src/server/kbn_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -83,7 +86,6 @@ export default class KbnServer {

// setup this.uiExports and this.uiBundles
uiMixin,
i18nMixin,
indexPatternsMixin,

// setup saved object routes
Expand Down
4 changes: 0 additions & 4 deletions src/ui/ui_exports/ui_export_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ export {
shareContextMenuExtensions,
} from './ui_app_extensions';

export {
translations,
} from './ui_i18n';

export {
link,
links,
Expand Down
24 changes: 0 additions & 24 deletions src/ui/ui_exports/ui_export_types/ui_i18n.js

This file was deleted.