Skip to content

Commit

Permalink
Split .i18nrc across src, packages, and examples (#8414)
Browse files Browse the repository at this point in the history
Also:
* Force validation of i18n even when no translations are available
* Allow including translations in built artifacts

Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki authored Oct 3, 2024
1 parent ec4b9d7 commit f3f007a
Show file tree
Hide file tree
Showing 22 changed files with 237 additions and 111 deletions.
77 changes: 0 additions & 77 deletions .i18nrc.json

This file was deleted.

12 changes: 12 additions & 0 deletions examples/.i18nrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"paths": {
"embeddableExamples": "embeddable_examples",
"expressionsExample": "expressions_example",
"multipleDataSourceExample": "multiple_data_source_examples",
"searchExamples": "search_examples",
"stateContainerExamples": "state_containers_examples",
"uiActionsExamples": "ui_action_examples",
"uiActionsExplorer": "ui_actions_explorer"
},
"translations": []
}
6 changes: 6 additions & 0 deletions packages/.i18nrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"paths": {
"flot": "osd-ui-shared-deps/flot_charts"
},
"translations": []
}
85 changes: 85 additions & 0 deletions src/.i18nrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"paths": {
"advancedSettings": "plugins/advanced_settings",
"apmOss": "plugins/apm_oss",
"charts": "plugins/charts",
"common.ui": "legacy/ui",
"console": "plugins/console",
"contentManagement": "plugins/content_management",
"core": "core",
"dashboard": "plugins/dashboard",
"data": "plugins/data",
"dataExplorer": "plugins/data_explorer",
"dataSourcesManagement": "plugins/data_source_management",
"devTools": "plugins/dev_tools",
"discover": "plugins/discover",
"embeddableApi": "plugins/embeddable",
"expressions": "plugins/expressions",
"home": "plugins/home",
"indexPatternManagement": "plugins/index_pattern_management",
"inputControl": "plugins/input_control_vis",
"inspector": "plugins/inspector",
"inspectorViews": "legacy/core_plugins/inspector_views",
"interpreter": "legacy/core_plugins/interpreter",
"management": [
"legacy/core_plugins/management",
"plugins/management",
"plugins/management_overview"
],
"maps_legacy": "plugins/maps_legacy",
"navigation": "plugins/navigation",
"newsfeed": "plugins/newsfeed",
"opensearch_dashboards_legacy": "plugins/opensearch_dashboards_legacy",
"opensearchDashboardsOverview": "plugins/opensearch_dashboards_overview",
"opensearch-dashboards-react": "plugins/opensearch_dashboards_react",
"opensearch_dashboards_react": "legacy/core_plugins/opensearch_dashboards_react",
"opensearch_dashboards_utils": "plugins/opensearch_dashboards_utils",
"opensearchUi": "plugins/opensearch_ui_shared",
"osd": "legacy/core_plugins/opensearch-dashboards",
"osdDocViews": "legacy/core_plugins/osd_doc_views",
"osdDocViewsLinks": "legacy/core_plugins/osd_doc_views_links",
"queryEnhancements": "plugins/query_enhancements",
"regionMap": "plugins/region_map",
"savedObjects": "plugins/saved_objects",
"savedObjectsManagement": "plugins/saved_objects_management",
"security": "plugins/security_oss",
"server": "legacy/server",
"share": "plugins/share",
"statusPage": "legacy/core_plugins/status_page",
"telemetry": [
"plugins/telemetry",
"plugins/telemetry_management_section"
],
"tileMap": "plugins/tile_map",
"timeline": [
"plugins/vis_type_timeline"
],
"uiActions": "plugins/ui_actions",
"usageCollection": "plugins/usage_collection",
"visAugmenter": "plugins/vis_augmenter",
"visBuilder": "plugins/vis_builder",
"visDefaultEditor": "plugins/vis_default_editor",
"visTypeMarkdown": "plugins/vis_type_markdown",
"visTypeMetric": "plugins/vis_type_metric",
"visTypeTable": "plugins/vis_type_table",
"visTypeTagCloud": "plugins/vis_type_tagcloud",
"visTypeTimeseries": "plugins/vis_type_timeseries",
"visTypeVega": "plugins/vis_type_vega",
"visTypeVislib": "plugins/vis_type_vislib",
"visTypeXy": "plugins/vis_type_xy",
"visualizations": "plugins/visualizations",
"visualize": "plugins/visualize",
"workspace": "plugins/workspace"
},
"exclude": [
"legacy/ui/ui_render/ui_render_mixin.js",
"plugins/home/public/application/components/tutorial",
"plugins/home/server/tutorials",
"core/server/rendering/views/template.tsx",
"plugins/data/public/search/errors/timeout_error.tsx",
"plugins/home/public/application/components/welcome.tsx",
"plugins/vis_type_timeline/server/series_functions/graphite.js",
"plugins/vis_type_timeseries/public/application/components/aggs/serial_diff.js"
],
"translations": []
}
10 changes: 10 additions & 0 deletions src/dev/build/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ it('build dist for current platform, without packages, by default', () => {
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -96,6 +97,7 @@ it('build dist for linux x64 platform, without packages, if --linux is passed',
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -126,6 +128,7 @@ it('build dist for linux arm64 platform, without packages, if --linux-arm is pas
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -156,6 +159,7 @@ it('build dist for darwin x64 platform, without packages, if --darwin is passed'
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -186,6 +190,7 @@ it('build dist for windows x64 platform, without packages, if --windows is passe
"windows": true,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -216,6 +221,7 @@ it('builds packages if --all-platforms is passed', () => {
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -246,6 +252,7 @@ it('limits packages if --rpm passed with --all-platforms', () => {
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -276,6 +283,7 @@ it('limits packages if --deb passed with --all-platforms', () => {
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -307,6 +315,7 @@ it('limits packages if --docker passed with --all-platforms', () => {
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down Expand Up @@ -338,6 +347,7 @@ it('limits packages if --docker passed with --skip-docker-ubi and --all-platform
"windows": false,
},
"versionQualifier": "",
"withTranslations": false,
},
"log": <ToolingLog>,
"showHelp": false,
Expand Down
2 changes: 2 additions & 0 deletions src/dev/build/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function readCliArgs(argv: string[]) {
'silent',
'debug',
'help',
'with-translations',
],
alias: {
v: 'verbose',
Expand Down Expand Up @@ -139,6 +140,7 @@ export function readCliArgs(argv: string[]) {
linuxArm: Boolean(flags['linux-arm']),
},
targetAllPlatforms: Boolean(flags['all-platforms']),
withTranslations: Boolean(flags['with-translations']),
};

return {
Expand Down
6 changes: 6 additions & 0 deletions src/dev/build/build_distributables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface BuildOptions {
versionQualifier: string | undefined;
targetAllPlatforms: boolean;
targetPlatforms: TargetPlatforms;
withTranslations: boolean;
}

export async function buildDistributables(log: ToolingLog, options: BuildOptions) {
Expand All @@ -70,6 +71,11 @@ export async function buildDistributables(log: ToolingLog, options: BuildOptions
* run platform-generic build tasks
*/
await run(Tasks.CopySource);

if (options.withTranslations) {
// control w/ --with-translations
await run(Tasks.CopyTranslations);
}
await run(Tasks.CopyBinScripts);
await run(Tasks.CreateEmptyDirsAndFiles);
await run(Tasks.CreateReadme);
Expand Down
1 change: 1 addition & 0 deletions src/dev/build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ if (showHelp) {
--release {dim Produce a release-ready distributable}
--version-qualifier {dim Suffix version with a qualifier}
--skip-node-download {dim Reuse existing downloads of node.js}
--with-translations {dim Include available translations}
--verbose,-v {dim Turn on verbose logging}
--no-debug {dim Turn off debug logging}
`) + '\n'
Expand Down
1 change: 0 additions & 1 deletion src/dev/build/tasks/copy_source_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const CopySource: Task = {
'config/opensearch_dashboards.yml',
'config/node.options',
'tsconfig*.json',
'.i18nrc.json',
'opensearch_dashboards.d.ts',
],
});
Expand Down
51 changes: 51 additions & 0 deletions src/dev/build/tasks/copy_translations_task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { i18nLoader } from '@osd/i18n';
import { write, Task } from '../lib';
import { getTranslationPaths } from '../../../legacy/server/i18n/get_translations_path';
import { I18N_RC, DEFAULT_DIRS_WITH_RC_FILES } from '../../i18n/constants';

const TRANSLATIONS_PATH = 'i18n';

export const CopyTranslations: Task = {
description: 'Copying translations into platform-generic build directory',

async run(config, log, build) {
const repoRoot = config.resolveFromRepo();

log.info('Gathering translations');

const allTranslationPaths = await getTranslationPaths({
cwd: repoRoot,
// `,.` is added for backward compatibility
// ToDo: Remove `,.` for next major release
glob: `{${DEFAULT_DIRS_WITH_RC_FILES.join(',')},.}/${I18N_RC}`,
});

i18nLoader.registerTranslationFiles(allTranslationPaths);

log.info('Combining translations');

const translationFiles: string[] = [];

for (const locale of i18nLoader.getRegisteredLocales()) {
const { formats, messages } = await i18nLoader.getTranslationsByLocale(locale);
const translationFilename = `${locale}.json`;
translationFiles.push(translationFilename);
await write(
build.resolvePath(`${TRANSLATIONS_PATH}/${translationFilename}`),
JSON.stringify({ formats, messages })
);
}

log.info('Generating translation manifest');

await write(
build.resolvePath(`${TRANSLATIONS_PATH}/${I18N_RC}`),
JSON.stringify({ translations: translationFiles })
);
},
};
1 change: 1 addition & 0 deletions src/dev/build/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export * from './build_opensearch_dashboards_platform_plugins';
export * from './build_packages_task';
export * from './clean_tasks';
export * from './copy_source_task';
export * from './copy_translations_task';
export * from './create_archives_sources_task';
export * from './create_archives_task';
export * from './create_empty_dirs_and_files_task';
Expand Down
Loading

0 comments on commit f3f007a

Please sign in to comment.