Skip to content
Snippets Groups Projects
Commit 1a8aabc9 authored by William Welling's avatar William Welling
Browse files

Translating app component content

parent 40562a50
No related branches found
No related tags found
No related merge requests found
<h3>DSpace</h3>
<h3>{{ 'title' | translate }}</h3>
<nav>
<a routerLinkActive="router-link-active" routerLink="home">Home</a>
<a routerLinkActive="router-link-active" routerLink="home">{{ 'nav.home' | translate }}</a>
</nav>
<div class="container-fluid">
<main>
<p>{{ 'example.with.data' | translate:data }}</p>
<p>{{ example }}</p>
<router-outlet></router-outlet>
</main>
</div>
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;
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment