-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(i18n): browser tab page title translations
- Loading branch information
1 parent
bb44d0e
commit 8a5346d
Showing
10 changed files
with
110 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Title } from '@angular/platform-browser'; | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot } from '@angular/router'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { filter } from 'rxjs/operators'; | ||
|
||
import { environment as env } from '@env/environment'; | ||
|
||
@Injectable() | ||
export class TitleService { | ||
constructor( | ||
private translateService: TranslateService, | ||
private title: Title | ||
) { | ||
} | ||
|
||
setTitle( | ||
snapshot: ActivatedRouteSnapshot, | ||
lazyTranslateService?: TranslateService | ||
) { | ||
let lastChild = snapshot; | ||
while (lastChild.children.length) { | ||
lastChild = lastChild.children[0]; | ||
} | ||
const { title } = lastChild.data; | ||
const translate = lazyTranslateService || this.translateService; | ||
if (title) { | ||
translate | ||
.get(title) | ||
.pipe(filter(translatedTitle => translatedTitle !== title)) | ||
.subscribe(translatedTitle => | ||
this.title.setTitle(`${translatedTitle} - ${env.appName}`) | ||
); | ||
} else { | ||
this.title.setTitle(env.appName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters