Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow for tree-shaking unused langauges translations in custom apps #19799

Merged
merged 21 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f50b551
add a script for generating translations.ts, and configs
Platonn Dec 20, 2024
d3f7ddd
modify script, and generate the files
Platonn Dec 20, 2024
7b75621
refactor: move all exports of @deprecated const <prefix>Translations …
Platonn Dec 20, 2024
98259c3
fix: add peer-dependency on @spartacus/core in @spartacus/assets
Platonn Dec 20, 2024
c4b6665
in the script, in function `generateLanguageIndex`, if the JSON filen…
Platonn Dec 20, 2024
71d682b
generate missing index.ts - after merging (and rebasing) the main bra…
Platonn Dec 20, 2024
6dc3188
fix(schematics): in fresh app use directly the EN translations `<pref…
Platonn Dec 20, 2024
86958a6
doc: use word 'please' in the @deprecated notice
Platonn Dec 20, 2024
f3b1a21
rename and move the script
Platonn Dec 20, 2024
cbce210
rename all 'translations-ts-generator.config' files to 'generate-tran…
Platonn Dec 20, 2024
ad66885
prettier: run prettier on the modified generated files
Platonn Dec 20, 2024
33d8319
delete script and its configs
Platonn Dec 20, 2024
4441800
Add license header
github-actions[bot] Dec 20, 2024
058ce32
fix(generate-translations-ts-2-json): workaround to not use translati…
Platonn Jan 7, 2025
d4f9aff
fix(assets): in tsconfig.lib.json update paths for @spartacus/core to…
Platonn Jan 7, 2025
05f7d76
Add license header
github-actions[bot] Jan 7, 2025
606905e
refactor(storefrontapp): use the new approach (with explicit langauge…
Platonn Jan 7, 2025
d6f8c02
Revert "fix(assets): in tsconfig.lib.json update paths for @spartacus…
Platonn Jan 7, 2025
9de3c36
Merge branch 'epic/tew-translation--script-v2' of github.com:SAP/spar…
Platonn Jan 7, 2025
9a13012
test(schematics): update snapshots to use new approach `i18n: { resou…
Platonn Jan 8, 2025
35fa2dc
Merge branch 'epic/tew-translation' of github.com:SAP/spartacus into …
Platonn Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 4 additions & 3 deletions .github/api-extractor-action/src/api-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ async function copyApiExtractorConfig(targetDir: string): Promise<void> {
*
* @returns object with name and the newName
*/
function updateNameInPackageJson(
path: string
): { name: string; newName: string } {
function updateNameInPackageJson(path: string): {
name: string;
newName: string;
} {
const packageContent = JSON.parse(fs.readFileSync(path, 'utf-8'));
const name: string = packageContent.name;
const newName = name.replace(/\//g, '_').replace(/\_/, '/');
Expand Down
16 changes: 16 additions & 0 deletions feature-libs/asm/assets/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { asmTranslationsEn } from './translations/translations';

export * from './translations/translations';

/**
* @deprecated Please use **specific language** translations (suffixed with language code) instead,
* like in the following example:
* ```diff
* i18n: {
* - resources: asmTranslations
* + resources: { en: asmTranslationsEn }
* }
* ```
*/
export const asmTranslations = {
en: asmTranslationsEn,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/cs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const cs = {
asm,
};
1 change: 0 additions & 1 deletion feature-libs/asm/assets/translations/de/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import asm from './asm.json';

export const de = {
asm,
};
1 change: 0 additions & 1 deletion feature-libs/asm/assets/translations/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import asm from './asm.json';

export const en = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/es/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const es = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/es_CO/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const es_CO = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/fr/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const fr = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/hi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const hi = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/hu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const hu = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/id/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const id = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/it/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const it = {
asm,
};
1 change: 0 additions & 1 deletion feature-libs/asm/assets/translations/ja/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import asm from './asm.json';

export const ja = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/ko/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const ko = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/pl/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const pl = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/pt/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const pt = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/ru/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const ru = {
asm,
};
33 changes: 19 additions & 14 deletions feature-libs/asm/assets/translations/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { TranslationChunksConfig, TranslationResources } from '@spartacus/core';
import { en } from './en/index';
import { ja } from './ja/index';
import { de } from './de/index';
import { zh } from './zh/index';
import { extractTranslationChunksConfig } from '@spartacus/core';
export const asmTranslationChunksConfig = extractTranslationChunksConfig(en);

export const asmTranslations: TranslationResources = {
en,
ja,
de,
zh,
};

export const asmTranslationChunksConfig: TranslationChunksConfig = {
asm: ['asm'],
};
export { cs as asmTranslationsCs } from './cs/index';
export { de as asmTranslationsDe } from './de/index';
export { en as asmTranslationsEn } from './en/index';
export { es as asmTranslationsEs } from './es/index';
export { es_CO as asmTranslationsEs_CO } from './es_CO/index';
export { fr as asmTranslationsFr } from './fr/index';
export { hi as asmTranslationsHi } from './hi/index';
export { hu as asmTranslationsHu } from './hu/index';
export { id as asmTranslationsId } from './id/index';
export { it as asmTranslationsIt } from './it/index';
export { ja as asmTranslationsJa } from './ja/index';
export { ko as asmTranslationsKo } from './ko/index';
export { pl as asmTranslationsPl } from './pl/index';
export { pt as asmTranslationsPt } from './pt/index';
export { ru as asmTranslationsRu } from './ru/index';
export { zh as asmTranslationsZh } from './zh/index';
export { zh_TW as asmTranslationsZh_TW } from './zh_TW/index';
1 change: 0 additions & 1 deletion feature-libs/asm/assets/translations/zh/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import asm from './asm.json';

export const zh = {
asm,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/assets/translations/zh_TW/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asm from './asm.json';
export const zh_TW = {
asm,
};
16 changes: 16 additions & 0 deletions feature-libs/asm/customer-360/assets/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { asmCustomer360TranslationsEn } from './translations/translations';

export * from './translations/translations';

/**
* @deprecated Please use **specific language** translations (suffixed with language code) instead,
* like in the following example:
* ```diff
* i18n: {
* - resources: asmCustomer360Translations
* + resources: { en: asmCustomer360TranslationsEn }
* }
* ```
*/
export const asmCustomer360Translations = {
en: asmCustomer360TranslationsEn,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/customer-360/assets/translations/cs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asmCustomer360 from './asmCustomer360.json';
export const cs = {
asmCustomer360,
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import asmCustomer360 from './asmCustomer360.json';

export const de = {
asmCustomer360,
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import asmCustomer360 from './asmCustomer360.json';

export const en = {
asmCustomer360,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/customer-360/assets/translations/es/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asmCustomer360 from './asmCustomer360.json';
export const es = {
asmCustomer360,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asmCustomer360 from './asmCustomer360.json';
export const es_CO = {
asmCustomer360,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/customer-360/assets/translations/fr/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asmCustomer360 from './asmCustomer360.json';
export const fr = {
asmCustomer360,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/customer-360/assets/translations/hi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asmCustomer360 from './asmCustomer360.json';
export const hi = {
asmCustomer360,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/customer-360/assets/translations/hu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asmCustomer360 from './asmCustomer360.json';
export const hu = {
asmCustomer360,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/customer-360/assets/translations/id/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asmCustomer360 from './asmCustomer360.json';
export const id = {
asmCustomer360,
};
11 changes: 11 additions & 0 deletions feature-libs/asm/customer-360/assets/translations/it/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import asmCustomer360 from './asmCustomer360.json';
export const it = {
asmCustomer360,
};
Loading
Loading