1.0.4 • Published 4 years ago

@ferhado/translator v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Angular Translator

Installation

npm install @ferhado/translator --save

Usage Example

app.module.ts

import { TranslatorModule } from '@ferhado/translator';

@NgModule({
  // ...
  
  imports: [
    // ...
    TranslatorModule.forRoot({
      allowedLocales: ["en", "de"],
      defaultLocale: "de"
    })
  ],
  bootstrap: [AppComponent]
})
 
export class AppModule { }

app.component.ts

import { Component, OnInit } from '@angular/core';
import { TranslatorService } from '@ferhado/tTranslator';

declare const require;

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
})

export class AppComponent implements OnInit {
  constructor(public tr: TranslatorService) { }

  ngOnInit() {
    this.setLanguage(this.tr.locale);
  }

  setLanguage(lang) {
    let translation = require(`../assets/i18n/${lang}.json`);
    this.tr.setTranslationObject(translation);
    this.tr.setLanguage(lang);
  }

}

app.component.html

<button (click)="setLanguage('en')">English</button>
<button (click)="setLanguage('de')">Deutsch</button>

<h1>{{'key' | tr}}</h1>
<h1>{{tr.locale}}</h1>
<h1>{{tr.dir}}</h1>
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago