Simple translate module for Angular 2 based on a blog post by Jecelyn Yeen (chybie). Features include support for fallback language, nested objects and interpolation.
npm install angular-simple-translateimport { TranslateModule } from 'angular-simple-translate';
...
@NgModule({
imports: [
TranslateModule,
...
],
...
})
export class YourModule { }en.ts
export const EN = {
"app": {
"title": "Angular-Simple-Translate Beispiel",
"greet": "Hello, %0 %1"
}
};de.ts
export const DE = {
"app": {
"title": "Angular-Simple-Translate Beispiel",
"greet": "Hallo, %0 %1"
}
};translations.ts
import { EN } from './en';
import { DE } from './de';
export const TRANSLATIONS = {
"en" : EN,
"de" : DE
}app.component.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
private readonly _translateService: TranslateService;
constructor(translateService: TranslateService) {
this._translateService = translateService;
}
ngOnInit() {
this._translateService.init(TRANSLATIONS, navigator.language, 'en', true);
}
}<h1>
{{ 'app.title' | translate }}
</h1>
{{ 'app.greet' | translate:['John', 'Doe'] }}var title = this._translateService.instant('app.title');
var greeting = this._translateService.instant('app.greet', ['John', 'Doe']);You can try out the Datepicker in the demo app built with Angular-CLI.
npm install -g angular-cli@latestnpm installng serveMIT