Define Translations
Out of the box, spartacus-mock uses the default english translations provided by spartacus itself. You can override these translations, enhance them with additional translations or add your own custom translations:
Override default translations
Open the file
src/mock-server/mock-data/translations/translations.ts(created by the setup schematics)Out of the box, the default translations from Spartacus Assets are imported in this file
Create a folder
enwithin thetranslationsfolderCreate a file
src/mock-server/mock-data/translations/en/product.tswith the following content
// src/mock-server/mock-data/translations/en/product.ts
// your custom translations for the chunk product
export const product = {
// your custom translations for the chunk product
// you can add any nested objects here, they get deep merged with the existing default translations
productSummary: {
id: 'ID (custom)',
},
};Create a file
src/mock-server/mock-data/translations/en/index.tswith the following content
// src/mock-server/mock-data/translations/en/index.ts
import { mergeDeep } from '@valantic/spartacus-mock';
import { translations } from '@spartacus/assets';
import { product } from './product';
export const en = {
...mergeDeep(translations['en'], { product }),
};Add the enhanced english chunks to the translations file
Add custom chunks for language EN
Open the file
src/mock-server/mock-data/translations/translations.tsCreate a folder
enwithin thetranslationsfolderCreate a file
src/mock-server/mock-data/translations/en/my-custom-chunk.tswith the following content
Create a file
src/mock-server/mock-data/translations/en/index.tswith the following content
Add the enhanced english chunks to the translations file
Use your new translation in the template:
{{'myCustomChunk.foo' | cxTranslate}}
Pro tip: Do not forget to add the new chunk to the translation chunk config of the spartacus configuration module.
Add translations for other languages
Open the file
src/mock-server/mock-data/translations/translations.tsand add adeproperty
Create a folder
dewithin thetranslationsfolderCreate a file
src/mock-server/mock-data/translations/de/index.tswith the following content
Create a file
src/mock-server/mock-data/translations/de/product.tswith the following content
Append your translations to your mockConfig in your
main.tsfile
Pro tip: If you want to have full control over the translations, you can also provide a custom handler for the translation endpoint as described in "Add Handlers for Endpoints"
Last updated