Skip to content

Ng2 translate

Charel92 edited this page Jul 18, 2016 · 3 revisions

Ng2 Translate

Here is a really easy tutorial for using NG2. Link

How to translate a word

  • Add to imports

import {TranslateService, TranslatePipe} from 'ng2-translate/ng2-translate';

  • Add e translate service to your constructor

` private translate: TranslateService`

  • In your @component section add a new pipe

pipes: [TranslatePipe]

  • You can use the pipe to translate in your .html-file

{{ "key" | translate }}

  • To get a translation in your .ts-file use

this.translate.instant("key");

Adding a new language to the app

  • Navigate to the www/assets/i18n/ and create a JSON-file named after the language you want to translate to.

  • You can copy the content form an other JSON-file to your new file, so you have already all the variabels you want to translate.

  • Translate the words on the right into the new language.

  • Go to app/components/setting.ts and add the new language to the changeLanguage(lang) function.

  • Add the Language in the setting.html file.