Skip to content

Commit ceccd4f

Browse files
Bamiehkibanamachine
authored andcommitted
[i18n] remove i18n html extractor (#115004)
1 parent 6e11540 commit ceccd4f

14 files changed

Lines changed: 36 additions & 508 deletions

File tree

src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_1/test_file_1.jsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/* eslint-disable */
22

3-
// Angular service
4-
i18n('plugin_1.id_1', { defaultMessage: 'Message 1' });
5-
63
// @kbn/i18n
7-
i18n.translate('plugin_1.id_2', {
8-
defaultMessage: 'Message 2',
4+
i18n.translate('plugin_1.id_1', {
5+
defaultMessage: 'Message 1',
96
description: 'Message description',
107
});
118

@@ -15,10 +12,10 @@ class Component extends PureComponent {
1512
return (
1613
<div>
1714
<FormattedMessage
18-
id="plugin_1.id_3"
19-
defaultMessage="Message 3"
15+
id="plugin_1.id_2"
16+
defaultMessage="Message 2"
2017
/>
21-
{intl.formatMessage({ id: 'plugin_1.id_4', defaultMessage: 'Message 4' })}
18+
{intl.formatMessage({ id: 'plugin_1.id_3', defaultMessage: 'Message 3' })}
2219
</div>
2320
);
2421
}

src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_1/test_file_4.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_2/test_file.html

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable */
2+
3+
i18n.translate('plugin_2.duplicate_id', { defaultMessage: 'Message 1' });
4+
5+
i18n.translate('plugin_2.duplicate_id', {
6+
defaultMessage: 'Message 2',
7+
description: 'Message description',
8+
});

src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_3/test_file.jsx renamed to src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_2_additional_path/test_file.jsx

File renamed without changes.

src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_3_additional_path/test_file.jsx

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/dev/i18n/__snapshots__/extract_default_translations.test.js.snap

Lines changed: 4 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dev/i18n/extract_default_translations.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import path from 'path';
1010

11-
import { extractHtmlMessages, extractCodeMessages } from './extractors';
11+
import { extractCodeMessages } from './extractors';
1212
import { globAsync, readFileAsync, normalizePath } from './utils';
1313

1414
import { createFailError, isFailError } from '@kbn/dev-utils';
@@ -59,33 +59,22 @@ export async function matchEntriesWithExctractors(inputPath, options = {}) {
5959
'**/*.d.ts',
6060
].concat(additionalIgnore);
6161

62-
const entries = await globAsync('*.{js,jsx,ts,tsx,html}', {
62+
const entries = await globAsync('*.{js,jsx,ts,tsx}', {
6363
cwd: inputPath,
6464
matchBase: true,
6565
ignore,
6666
mark,
6767
absolute,
6868
});
6969

70-
const { htmlEntries, codeEntries } = entries.reduce(
71-
(paths, entry) => {
72-
const resolvedPath = path.resolve(inputPath, entry);
70+
const codeEntries = entries.reduce((paths, entry) => {
71+
const resolvedPath = path.resolve(inputPath, entry);
72+
paths.push(resolvedPath);
7373

74-
if (resolvedPath.endsWith('.html')) {
75-
paths.htmlEntries.push(resolvedPath);
76-
} else {
77-
paths.codeEntries.push(resolvedPath);
78-
}
79-
80-
return paths;
81-
},
82-
{ htmlEntries: [], codeEntries: [] }
83-
);
74+
return paths;
75+
}, []);
8476

85-
return [
86-
[htmlEntries, extractHtmlMessages],
87-
[codeEntries, extractCodeMessages],
88-
];
77+
return [[codeEntries, extractCodeMessages]];
8978
}
9079

9180
export async function extractMessagesFromPathToMap(inputPath, targetMap, config, reporter) {

src/dev/i18n/extract_default_translations.test.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ const fixturesPath = path.resolve(__dirname, '__fixtures__', 'extract_default_tr
1818
const pluginsPaths = [
1919
path.join(fixturesPath, 'test_plugin_1'),
2020
path.join(fixturesPath, 'test_plugin_2'),
21-
path.join(fixturesPath, 'test_plugin_3'),
22-
path.join(fixturesPath, 'test_plugin_3_additional_path'),
21+
path.join(fixturesPath, 'test_plugin_2_additional_path'),
2322
];
2423

2524
const config = {
2625
paths: {
2726
plugin_1: ['src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_1'],
28-
plugin_2: ['src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_2'],
29-
plugin_3: [
30-
'src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_3',
31-
'src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_3_additional_path',
27+
plugin_2: [
28+
'src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_2',
29+
'src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_2_additional_path',
3230
],
3331
},
3432
exclude: [],
@@ -44,7 +42,7 @@ describe('dev/i18n/extract_default_translations', () => {
4442
});
4543

4644
test('throws on id collision', async () => {
47-
const [, , pluginPath] = pluginsPaths;
45+
const [, pluginPath] = pluginsPaths;
4846
const reporter = new ErrorReporter();
4947

5048
await expect(
@@ -57,20 +55,20 @@ describe('dev/i18n/extract_default_translations', () => {
5755
const id = 'plugin_2.message-id';
5856
const filePath = path.resolve(
5957
__dirname,
60-
'__fixtures__/extract_default_translations/test_plugin_2/test_file.html'
58+
'__fixtures__/extract_default_translations/test_plugin_2/test_file.jsx'
6159
);
6260
expect(() => validateMessageNamespace(id, filePath, config.paths)).not.toThrow();
6361
});
6462

6563
test('validates message namespace with multiple paths', () => {
66-
const id = 'plugin_3.message-id';
64+
const id = 'plugin_2.message-id';
6765
const filePath1 = path.resolve(
6866
__dirname,
69-
'__fixtures__/extract_default_translations/test_plugin_3/test_file.html'
67+
'__fixtures__/extract_default_translations/test_plugin_2/test_file.jsx'
7068
);
7169
const filePath2 = path.resolve(
7270
__dirname,
73-
'__fixtures__/extract_default_translations/test_plugin_3_additional_path/test_file.html'
71+
'__fixtures__/extract_default_translations/test_plugin_2_additional_path/test_file.jsx'
7472
);
7573
expect(() => validateMessageNamespace(id, filePath1, config.paths)).not.toThrow();
7674
expect(() => validateMessageNamespace(id, filePath2, config.paths)).not.toThrow();
@@ -81,7 +79,7 @@ describe('dev/i18n/extract_default_translations', () => {
8179
const id = 'wrong_plugin_namespace.message-id';
8280
const filePath = path.resolve(
8381
__dirname,
84-
'__fixtures__/extract_default_translations/test_plugin_2/test_file.html'
82+
'__fixtures__/extract_default_translations/test_plugin_2/test_file.jsx'
8583
);
8684

8785
expect(() => validateMessageNamespace(id, filePath, config.paths, { report })).not.toThrow();

src/dev/i18n/extractors/__snapshots__/html.test.js.snap

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)