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
en
within thetranslations
folderCreate a file
src/mock-server/mock-data/translations/en/product.ts
with the following content
Create a file
src/mock-server/mock-data/translations/en/index.ts
with the following content
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.ts
Create a folder
en
within thetranslations
folderCreate a file
src/mock-server/mock-data/translations/en/my-custom-chunk.ts
with the following content
Create a file
src/mock-server/mock-data/translations/en/index.ts
with 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.ts
and add ade
property
Create a folder
de
within thetranslations
folderCreate a file
src/mock-server/mock-data/translations/de/index.ts
with the following content
Create a file
src/mock-server/mock-data/translations/de/product.ts
with the following content
Append your translations to your mockConfig in your
main.ts
file
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