Skip to content

Commit

Permalink
Init I18n before Notifications start (elastic#23902)
Browse files Browse the repository at this point in the history
* Init I18n before Notifications start

* Remove i18n initialization in AngularJS since it will be already initialized in CoreSystem

* Remove unused translationsApi

* Remove redundant i18n.init invocation

* Remove i18n tests since  i18n.init was removed and input params for AppBootstrap were changed

* Move i18n initialization to the entry file.
  • Loading branch information
maryia-lapata authored Oct 19, 2018
1 parent 03d14a7 commit 4b9e13c
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 81 deletions.
35 changes: 0 additions & 35 deletions src/ui/public/chrome/api/translations.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/ui/public/chrome/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import controlsApi from './api/controls';
import { initChromeNavApi } from './api/nav';
import templateApi from './api/template';
import themeApi from './api/theme';
import translationsApi from './api/translations';
import { initChromeXsrfApi } from './api/xsrf';
import { initUiSettingsApi } from './api/ui_settings';
import { initLoadingCountApi } from './api/loading_count';
Expand Down Expand Up @@ -73,7 +72,6 @@ initAngularApi(chrome, internals);
controlsApi(chrome, internals);
templateApi(chrome, internals);
themeApi(chrome, internals);
translationsApi(chrome, internals);

const waitForBootstrap = new Promise(resolve => {
chrome.bootstrap = function (targetDomElement) {
Expand Down
6 changes: 1 addition & 5 deletions src/ui/public/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { uiModules } from 'ui/modules';
import { metadata } from 'ui/metadata';
import {
I18nProvider,
i18nFilter,
Expand All @@ -28,7 +27,4 @@ import {
uiModules.get('i18n')
.provider('i18n', I18nProvider)
.filter('i18n', i18nFilter)
.directive('i18nId', i18nDirective)
.config((i18nProvider) => {
i18nProvider.init(metadata.translations);
});
.directive('i18nId', i18nDirective);
6 changes: 5 additions & 1 deletion src/ui/ui_bundles/app_entry_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ import 'whatwg-fetch';
import 'abortcontroller-polyfill';
import 'childnode-remove-polyfill';
import { i18n } from '@kbn/i18n';
import { CoreSystem } from '__kibanaCore__'
const injectedMetadata = JSON.parse(document.querySelector('kbn-injected-metadata').getAttribute('data'));
i18n.init(injectedMetadata.legacyMetadata.translations);
new CoreSystem({
injectedMetadata: JSON.parse(document.querySelector('kbn-injected-metadata').getAttribute('data')),
injectedMetadata,
rootDomElement: document.body,
requireLegacyFiles: () => {
${bundle.getRequires().join('\n ')}
Expand Down
3 changes: 1 addition & 2 deletions src/ui/ui_render/bootstrap/app_bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ import { resolve } from 'path';
import { i18n } from '@kbn/i18n';

export class AppBootstrap {
constructor({ templateData, translations }) {
constructor({ templateData }) {
this.templateData = templateData;
this._rawTemplate = undefined;
i18n.init(translations);
}

async getJsFile() {
Expand Down
34 changes: 0 additions & 34 deletions src/ui/ui_render/bootstrap/app_bootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ describe('ui_render/AppBootstrap', () => {
expect(contents).toContain('123');
expect(contents).toContain('/foo/bar');
});

test('supports i18n', async () => {
expect.assertions(1);

const bootstrap = new AppBootstrap(mockConfig());
const contents = await bootstrap.getJsFile();

expect(contents).toContain('translated foo');
});
});

describe('getJsFileHash()', () => {
Expand Down Expand Up @@ -121,36 +112,11 @@ describe('ui_render/AppBootstrap', () => {
expect(hash2).toHaveLength(40);
expect(hash2).not.toEqual(hash1);
});

test('resolves to different 40 character string with different translations', async () => {
expect.assertions(3);

const bootstrap1 = new AppBootstrap(mockConfig());
const hash1 = await bootstrap1.getJsFileHash();

const config2 = {
...mockConfig(),
translations: {
locale: 'en',
foo: 'not translated foo'
}
};
const bootstrap2 = new AppBootstrap(config2);
const hash2 = await bootstrap2.getJsFileHash();

expect(typeof hash2).toEqual('string');
expect(hash2).toHaveLength(40);
expect(hash2).not.toEqual(hash1);
});
});
});

function mockConfig() {
return {
translations: {
locale: 'en',
foo: 'translated foo'
},
templateData: {
appId: 123,
bundlePath: '/foo/bar'
Expand Down
3 changes: 1 addition & 2 deletions src/ui/ui_render/ui_render_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export function uiRenderMixin(kbnServer, server, config) {
appId: app.getId(),
bundlePath,
styleSheetPaths,
},
translations: await server.getUiTranslations()
}
});

const body = await bootstrap.getJsFile();
Expand Down

0 comments on commit 4b9e13c

Please sign in to comment.