[ADF-3028] i18n support for title service (#3342)

* i18n support for title service

* cleanup tests

* update tests
This commit is contained in:
Denys Vuika
2018-05-18 10:51:13 +01:00
committed by Eugenio Romano
parent b00eb1433e
commit 53cf5acc86
6 changed files with 75 additions and 31 deletions

View File

@@ -18,22 +18,41 @@
import { Injectable } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { AppConfigService } from '../app-config/app-config.service';
import { TranslationService } from './translation.service';
@Injectable()
export class PageTitleService {
private originalTitle: string = '';
private translatedTitle: string = '';
constructor(
private titleService: Title,
private appConfig: AppConfigService) {}
private appConfig: AppConfigService,
private translationService: TranslationService) {
translationService.translate.onLangChange.subscribe(() => this.onLanguageChanged());
}
/**
* Sets the page title.
* @param value The new title
*/
setTitle(value: string = '') {
const name = this.appConfig.get('application.name') || 'Alfresco ADF Application';
const title = value ? `${value} - ${name}` : `${name}`;
this.originalTitle = value;
this.translatedTitle = this.translationService.instant(value);
this.updateTitle();
}
private onLanguageChanged() {
this.translatedTitle = this.translationService.instant(this.originalTitle);
this.updateTitle();
}
private updateTitle() {
const name = this.appConfig.get('application.name') || 'Alfresco ADF Application';
const title = this.translatedTitle ? `${this.translatedTitle} - ${name}` : `${name}`;
this.titleService.setTitle(title);
}
}