Drift Angular
Search…
Internationalization

Overview

The internationalization (i18n) library for Angular by ngx-translate

How to add a new language

To register new language we have to update given below files:
    src/assets/i18n/*.json
    src/app/app.component.ts
Duplicate en.json file and create a new language file in src/assets/i18n/*.json. The new file name and the language name must be matched.
Register the language by adding its name to languages array.
1
translate.addLangs(['en', 'es', 'new lang name']);
Copied!

How to use

The translator understands nested JSON objects as defined in src/assets/i18n/*.json. This means that you can have a translation that looks like this:
{ "HOME": { "HELLO": "hello " } }
You can then access the value by using the dot notation, in this case HOME.HELLO.
1
<div [translate]="'HOME.HELLO'" [translateParams]="{value: 'world'}"></div>
Copied!
Last modified 1yr ago