Options
All
  • Public
  • Public/Protected
  • All
Menu

ng2-translator

ng2-translator

NPM version Build Status Coverage Status Dependency Status devDependency Status GitHub license Gitter

ng2-translator is a simple translation service and directive that manages multiple languages

import { Component } from '@angular/core';
import { Translator, TranslatorComponent } from 'ng2-translator';

@Component({
  selector: 'app',
  template: `
      <h2><wf-translate id="HEADER"></wf-translate></h2>
      <button (click)="changeLang('de')">In German, please!</button>
    `,
  directives: [TranslatorComponent],
  providers: [Translator]
})
export class AppComponent {
  constructor (private translator: Translator){}

  public changeLang(lang: string) {
    this.translator.setLanguage("de");
  }

  private initTranslator() {
    this.translator.setAvailableLanguages(["en", "de"]);
    this.translator.setTranslation("en", { HEADER: "Headline" });
    this.translator.setTranslation("de", { HEADER: "Überschrift" });
    this.translator.guessLanguage();
  }
}

CDN

The module should be available via unpkg at https://unpkg.com/ng2-translator

No guarantees for uptime or anything like that, though.

API

The module can be required as a CommonJS module. For usage details, read the documentation.