Skip to content

Commit

Permalink
[i18n] remove i18n html extractor (#115004)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh authored Oct 19, 2021
1 parent adbb808 commit 9caab58
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 508 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* eslint-disable */

// Angular service
i18n('plugin_1.id_1', { defaultMessage: 'Message 1' });

// @kbn/i18n
i18n.translate('plugin_1.id_2', {
defaultMessage: 'Message 2',
i18n.translate('plugin_1.id_1', {
defaultMessage: 'Message 1',
description: 'Message description',
});

Expand All @@ -15,10 +12,10 @@ class Component extends PureComponent {
return (
<div>
<FormattedMessage
id="plugin_1.id_3"
defaultMessage="Message 3"
id="plugin_1.id_2"
defaultMessage="Message 2"
/>
{intl.formatMessage({ id: 'plugin_1.id_4', defaultMessage: 'Message 4' })}
{intl.formatMessage({ id: 'plugin_1.id_3', defaultMessage: 'Message 3' })}
</div>
);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable */

i18n.translate('plugin_2.duplicate_id', { defaultMessage: 'Message 1' });

i18n.translate('plugin_2.duplicate_id', {
defaultMessage: 'Message 2',
description: 'Message description',
});

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 8 additions & 19 deletions src/dev/i18n/extract_default_translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import path from 'path';

import { extractHtmlMessages, extractCodeMessages } from './extractors';
import { extractCodeMessages } from './extractors';
import { globAsync, readFileAsync, normalizePath } from './utils';

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

const entries = await globAsync('*.{js,jsx,ts,tsx,html}', {
const entries = await globAsync('*.{js,jsx,ts,tsx}', {
cwd: inputPath,
matchBase: true,
ignore,
mark,
absolute,
});

const { htmlEntries, codeEntries } = entries.reduce(
(paths, entry) => {
const resolvedPath = path.resolve(inputPath, entry);
const codeEntries = entries.reduce((paths, entry) => {
const resolvedPath = path.resolve(inputPath, entry);
paths.push(resolvedPath);

if (resolvedPath.endsWith('.html')) {
paths.htmlEntries.push(resolvedPath);
} else {
paths.codeEntries.push(resolvedPath);
}

return paths;
},
{ htmlEntries: [], codeEntries: [] }
);
return paths;
}, []);

return [
[htmlEntries, extractHtmlMessages],
[codeEntries, extractCodeMessages],
];
return [[codeEntries, extractCodeMessages]];
}

export async function extractMessagesFromPathToMap(inputPath, targetMap, config, reporter) {
Expand Down
22 changes: 10 additions & 12 deletions src/dev/i18n/extract_default_translations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ const fixturesPath = path.resolve(__dirname, '__fixtures__', 'extract_default_tr
const pluginsPaths = [
path.join(fixturesPath, 'test_plugin_1'),
path.join(fixturesPath, 'test_plugin_2'),
path.join(fixturesPath, 'test_plugin_3'),
path.join(fixturesPath, 'test_plugin_3_additional_path'),
path.join(fixturesPath, 'test_plugin_2_additional_path'),
];

const config = {
paths: {
plugin_1: ['src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_1'],
plugin_2: ['src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_2'],
plugin_3: [
'src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_3',
'src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_3_additional_path',
plugin_2: [
'src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_2',
'src/dev/i18n/__fixtures__/extract_default_translations/test_plugin_2_additional_path',
],
},
exclude: [],
Expand All @@ -44,7 +42,7 @@ describe('dev/i18n/extract_default_translations', () => {
});

test('throws on id collision', async () => {
const [, , pluginPath] = pluginsPaths;
const [, pluginPath] = pluginsPaths;
const reporter = new ErrorReporter();

await expect(
Expand All @@ -57,20 +55,20 @@ describe('dev/i18n/extract_default_translations', () => {
const id = 'plugin_2.message-id';
const filePath = path.resolve(
__dirname,
'__fixtures__/extract_default_translations/test_plugin_2/test_file.html'
'__fixtures__/extract_default_translations/test_plugin_2/test_file.jsx'
);
expect(() => validateMessageNamespace(id, filePath, config.paths)).not.toThrow();
});

test('validates message namespace with multiple paths', () => {
const id = 'plugin_3.message-id';
const id = 'plugin_2.message-id';
const filePath1 = path.resolve(
__dirname,
'__fixtures__/extract_default_translations/test_plugin_3/test_file.html'
'__fixtures__/extract_default_translations/test_plugin_2/test_file.jsx'
);
const filePath2 = path.resolve(
__dirname,
'__fixtures__/extract_default_translations/test_plugin_3_additional_path/test_file.html'
'__fixtures__/extract_default_translations/test_plugin_2_additional_path/test_file.jsx'
);
expect(() => validateMessageNamespace(id, filePath1, config.paths)).not.toThrow();
expect(() => validateMessageNamespace(id, filePath2, config.paths)).not.toThrow();
Expand All @@ -81,7 +79,7 @@ describe('dev/i18n/extract_default_translations', () => {
const id = 'wrong_plugin_namespace.message-id';
const filePath = path.resolve(
__dirname,
'__fixtures__/extract_default_translations/test_plugin_2/test_file.html'
'__fixtures__/extract_default_translations/test_plugin_2/test_file.jsx'
);

expect(() => validateMessageNamespace(id, filePath, config.paths, { report })).not.toThrow();
Expand Down
77 changes: 0 additions & 77 deletions src/dev/i18n/extractors/__snapshots__/html.test.js.snap

This file was deleted.

Loading

0 comments on commit 9caab58

Please sign in to comment.