-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* migrate i18n mixin to KP * directly load the config from i18n service * add base tests * update telemetry schema * update legacy telemetry schema * fix server tests * use paths from config service instead of manually loading the plugin config * add tests for get_translation_paths * add tests for i18n service * add plugin service test * update generated doc * improve tsdoc
- Loading branch information
1 parent
b2d6b66
commit f49ee06
Showing
55 changed files
with
709 additions
and
202 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-core-server.coresetup.i18n.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreSetup](./kibana-plugin-core-server.coresetup.md) > [i18n](./kibana-plugin-core-server.coresetup.i18n.md) | ||
|
||
## CoreSetup.i18n property | ||
|
||
[I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
i18n: I18nServiceSetup; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...development/core/server/kibana-plugin-core-server.i18nservicesetup.getlocale.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) > [getLocale](./kibana-plugin-core-server.i18nservicesetup.getlocale.md) | ||
|
||
## I18nServiceSetup.getLocale() method | ||
|
||
Return the locale currently in use. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getLocale(): string; | ||
``` | ||
<b>Returns:</b> | ||
|
||
`string` | ||
|
17 changes: 17 additions & 0 deletions
17
...t/core/server/kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) > [getTranslationFiles](./kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md) | ||
|
||
## I18nServiceSetup.getTranslationFiles() method | ||
|
||
Return the absolute paths to translation files currently in use. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getTranslationFiles(): string[]; | ||
``` | ||
<b>Returns:</b> | ||
|
||
`string[]` | ||
|
20 changes: 20 additions & 0 deletions
20
docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) | ||
|
||
## I18nServiceSetup interface | ||
|
||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface I18nServiceSetup | ||
``` | ||
|
||
## Methods | ||
|
||
| Method | Description | | ||
| --- | --- | | ||
| [getLocale()](./kibana-plugin-core-server.i18nservicesetup.getlocale.md) | Return the locale currently in use. | | ||
| [getTranslationFiles()](./kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md) | Return the absolute paths to translation files currently in use. | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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 { getKibanaTranslationFiles } from './get_kibana_translation_files'; | ||
import { getTranslationPaths } from './get_translation_paths'; | ||
|
||
const mockGetTranslationPaths = getTranslationPaths as jest.Mock; | ||
|
||
jest.mock('./get_translation_paths', () => ({ | ||
getTranslationPaths: jest.fn().mockResolvedValue([]), | ||
})); | ||
jest.mock('../utils', () => ({ | ||
fromRoot: jest.fn().mockImplementation((path: string) => path), | ||
})); | ||
|
||
const locale = 'en'; | ||
|
||
describe('getKibanaTranslationPaths', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('calls getTranslationPaths against kibana root and kibana-extra', async () => { | ||
await getKibanaTranslationFiles(locale, []); | ||
|
||
expect(mockGetTranslationPaths).toHaveBeenCalledTimes(2); | ||
|
||
expect(mockGetTranslationPaths).toHaveBeenCalledWith({ | ||
cwd: '.', | ||
nested: true, | ||
}); | ||
|
||
expect(mockGetTranslationPaths).toHaveBeenCalledWith({ | ||
cwd: '../kibana-extra', | ||
nested: true, | ||
}); | ||
}); | ||
|
||
it('calls getTranslationPaths for each config returned in plugin.paths and plugins.scanDirs', async () => { | ||
const pluginPaths = ['/path/to/pluginA', '/path/to/pluginB']; | ||
|
||
await getKibanaTranslationFiles(locale, pluginPaths); | ||
|
||
expect(mockGetTranslationPaths).toHaveBeenCalledTimes(2 + pluginPaths.length); | ||
|
||
pluginPaths.forEach((pluginPath) => { | ||
expect(mockGetTranslationPaths).toHaveBeenCalledWith({ | ||
cwd: pluginPath, | ||
nested: false, | ||
}); | ||
}); | ||
}); | ||
|
||
it('only return files for specified locale', async () => { | ||
mockGetTranslationPaths.mockResolvedValueOnce(['/root/en.json', '/root/fr.json']); | ||
mockGetTranslationPaths.mockResolvedValueOnce([ | ||
'/kibana-extra/en.json', | ||
'/kibana-extra/fr.json', | ||
]); | ||
|
||
const translationFiles = await getKibanaTranslationFiles('en', []); | ||
|
||
expect(translationFiles).toEqual(['/root/en.json', '/kibana-extra/en.json']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const globbyMock = jest.fn(); | ||
jest.doMock('globby', () => globbyMock); | ||
|
||
export const readFileMock = jest.fn(); | ||
jest.doMock('./fs', () => ({ | ||
readFile: readFileMock, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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 { resolve, join } from 'path'; | ||
import { globbyMock, readFileMock } from './get_translation_paths.test.mocks'; | ||
import { getTranslationPaths } from './get_translation_paths'; | ||
|
||
describe('getTranslationPaths', () => { | ||
beforeEach(() => { | ||
globbyMock.mockReset(); | ||
readFileMock.mockReset(); | ||
|
||
globbyMock.mockResolvedValue([]); | ||
readFileMock.mockResolvedValue('{}'); | ||
}); | ||
|
||
it('calls `globby` with the correct parameters', async () => { | ||
getTranslationPaths({ cwd: '/some/cwd', nested: false }); | ||
|
||
expect(globbyMock).toHaveBeenCalledTimes(1); | ||
expect(globbyMock).toHaveBeenCalledWith('.i18nrc.json', { cwd: '/some/cwd' }); | ||
|
||
globbyMock.mockClear(); | ||
|
||
await getTranslationPaths({ cwd: '/other/cwd', nested: true }); | ||
|
||
expect(globbyMock).toHaveBeenCalledTimes(1); | ||
expect(globbyMock).toHaveBeenCalledWith('*/.i18nrc.json', { cwd: '/other/cwd' }); | ||
}); | ||
|
||
it('calls `readFile` for each entry returned by `globby`', async () => { | ||
const entries = [join('pathA', '.i18nrc.json'), join('pathB', '.i18nrc.json')]; | ||
globbyMock.mockResolvedValue(entries); | ||
|
||
const cwd = '/kibana-extra'; | ||
|
||
await getTranslationPaths({ cwd, nested: true }); | ||
|
||
expect(readFileMock).toHaveBeenCalledTimes(2); | ||
|
||
expect(readFileMock).toHaveBeenNthCalledWith(1, resolve(cwd, entries[0]), 'utf8'); | ||
expect(readFileMock).toHaveBeenNthCalledWith(2, resolve(cwd, entries[1]), 'utf8'); | ||
}); | ||
|
||
it('returns the absolute path to the translation files', async () => { | ||
const entries = ['.i18nrc.json']; | ||
globbyMock.mockResolvedValue(entries); | ||
|
||
const i18nFileContent = { | ||
translations: ['translations/en.json', 'translations/fr.json'], | ||
}; | ||
readFileMock.mockResolvedValue(JSON.stringify(i18nFileContent)); | ||
|
||
const cwd = '/cwd'; | ||
|
||
const translationPaths = await getTranslationPaths({ cwd, nested: true }); | ||
|
||
expect(translationPaths).toEqual([ | ||
resolve(cwd, 'translations/en.json'), | ||
resolve(cwd, 'translations/fr.json'), | ||
]); | ||
}); | ||
|
||
it('throws if i18nrc parsing fails', async () => { | ||
globbyMock.mockResolvedValue(['.i18nrc.json']); | ||
readFileMock.mockRejectedValue(new Error('error parsing file')); | ||
|
||
await expect( | ||
getTranslationPaths({ cwd: '/cwd', nested: true }) | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"Failed to parse .i18nrc.json file at /cwd/.i18nrc.json"` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.