From 1a8aabc996e4b53b1fb9b5ab01195e4a0e61234e Mon Sep 17 00:00:00 2001 From: William Welling Date: Thu, 1 Dec 2016 13:08:23 -0600 Subject: [PATCH] Translating app component content --- src/app/app.component.html | 6 ++++-- src/app/app.component.ts | 29 ++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index a7d039d11d..a83351f943 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,9 +1,11 @@ -

DSpace

+

{{ 'title' | translate }}

+

{{ 'example.with.data' | translate:data }}

+

{{ example }}

diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8951b4881e..215968ced2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,11 +1,34 @@ -import { Component, ChangeDetectionStrategy, ViewEncapsulation } from '@angular/core'; +import { Component, ChangeDetectionStrategy, OnInit, ViewEncapsulation } from '@angular/core'; + +import { TranslateService } from 'ng2-translate'; @Component({ changeDetection: ChangeDetectionStrategy.Default, encapsulation: ViewEncapsulation.Emulated, selector: 'ds-app', templateUrl: './app.component.html', - styleUrls: [ './app.component.scss' ] + styleUrls: ['./app.component.scss'] }) -export class AppComponent { +export class AppComponent implements OnInit { + + example: string; + + data: any = { + greeting: 'Hello', + recipient: 'World' + } + + constructor(public translate: TranslateService) { + // this language will be used as a fallback when a translation isn't found in the current language + translate.setDefaultLang('en'); + // the lang to use, if the lang isn't available, it will use the current loader to get them + translate.use('en'); + } + + ngOnInit() { + this.translate.get('example.with.data', { greeting: 'Hello', recipient: 'DSpace' }).subscribe((res: string) => { + this.example = res; + }); + } + }