Files
cbsnexora/docs/i18n.md
Ralph HopmanandAdam Saghy e3fbf8b81d build: Use prettier for markdown
Stop ignoring .md files in prettier and fix existing issues.
2024-12-18 17:09:22 +01:00

1.8 KiB

I18n

The internationalization of the application is managed by ngx-translate.

Adding translatable strings

In HTML templates

Use the translate directive on an HTML element to automatically translate its content:

<span translate>This text will be translated.</span>

You can also use the translate pipe if needed:

<button title="{{'Add item' | translate}}">+</button>

In TypeScript code

If you need to translate strings in JavaScript code, import the TranslateService dependency and use the asynchronous get() method:

let title;
translateService.get('My page title').subscribe((res: string) => {
  title = res;
});

or TranslateService dependency and use the asynchronous instant() method:

const title: string = translateService.instant('My page title');

Extracting strings to translate

Once you are ready to translate your app, just run npm translations:extract. It will create a template.json file in the src/assets/translations folder.

You can then use any text or code editor to generate the .json files for each of your supported languages, and put them in the src/assets/translations folder.

Do no forget to edit the files in src/environment to add the supported languages of your application.

These are the Language available now:

Language Code File
Czech cs cs-CS.json
German de de-DE.json
English en en-US.json
Spanish es es-MX.json
French fr fr-FR.json
Italian it it-IT.json
Korean ko ko-KO.json
Lithuanian li li-LI.json
Latvian lv lv-LV.json
Nepali ne ne-NE.json
Portuguese pt pt-PT.json
Swahili sw sw-SW.json