aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/app.component.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-06-02 15:21:36 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-04 09:05:44 +0200
commit140ea386dea49220f4cdd5b67027e8d30eee1b06 (patch)
treeddb7b510aa4ea80382d5b4360856d9ee53e6afaf /client/src/app/app.component.ts
parent3092e9bbb05fe292fd13bc685b89069c3dda55d9 (diff)
downloadPeerTube-140ea386dea49220f4cdd5b67027e8d30eee1b06.tar.gz
PeerTube-140ea386dea49220f4cdd5b67027e8d30eee1b06.tar.zst
PeerTube-140ea386dea49220f4cdd5b67027e8d30eee1b06.zip
inject lang in document to match current locale
Diffstat (limited to 'client/src/app/app.component.ts')
-rw-r--r--client/src/app/app.component.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts
index a464e90fa..aba91aad2 100644
--- a/client/src/app/app.component.ts
+++ b/client/src/app/app.component.ts
@@ -1,13 +1,13 @@
1import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core' 1import { Component, OnInit, ViewChild, AfterViewInit, Inject } from '@angular/core'
2import { DomSanitizer, SafeHtml } from '@angular/platform-browser' 2import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
3import { Event, GuardsCheckStart, NavigationEnd, Router, Scroll } from '@angular/router' 3import { Event, GuardsCheckStart, NavigationEnd, Router, Scroll } from '@angular/router'
4import { AuthService, RedirectService, ServerService, ThemeService } from '@app/core' 4import { AuthService, RedirectService, ServerService, ThemeService } from '@app/core'
5import { is18nPath } from '../../../shared/models/i18n' 5import { is18nPath, getShortLocale } from '../../../shared/models/i18n'
6import { ScreenService } from '@app/shared/misc/screen.service' 6import { ScreenService } from '@app/shared/misc/screen.service'
7import { filter, map, pairwise, first } from 'rxjs/operators' 7import { filter, map, pairwise, first } from 'rxjs/operators'
8import { Hotkey, HotkeysService } from 'angular2-hotkeys' 8import { Hotkey, HotkeysService } from 'angular2-hotkeys'
9import { I18n } from '@ngx-translate/i18n-polyfill' 9import { I18n } from '@ngx-translate/i18n-polyfill'
10import { PlatformLocation, ViewportScroller } from '@angular/common' 10import { PlatformLocation, ViewportScroller, DOCUMENT } from '@angular/common'
11import { PluginService } from '@app/core/plugins/plugin.service' 11import { PluginService } from '@app/core/plugins/plugin.service'
12import { HooksService } from '@app/core/plugins/hooks.service' 12import { HooksService } from '@app/core/plugins/hooks.service'
13import { NgbModal } from '@ng-bootstrap/ng-bootstrap' 13import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
@@ -42,6 +42,7 @@ export class AppComponent implements OnInit, AfterViewInit {
42 private serverConfig: ServerConfig 42 private serverConfig: ServerConfig
43 43
44 constructor ( 44 constructor (
45 @Inject(DOCUMENT) private document: Document,
45 private i18n: I18n, 46 private i18n: I18n,
46 private viewportScroller: ViewportScroller, 47 private viewportScroller: ViewportScroller,
47 private router: Router, 48 private router: Router,
@@ -170,6 +171,16 @@ export class AppComponent implements OnInit, AfterViewInit {
170 filter(pathname => !pathname || pathname === '/' || is18nPath(pathname)) 171 filter(pathname => !pathname || pathname === '/' || is18nPath(pathname))
171 ).subscribe(() => this.redirectService.redirectToHomepage(true)) 172 ).subscribe(() => this.redirectService.redirectToHomepage(true))
172 173
174 navigationEndEvent.pipe(
175 map(() => window.location.pathname),
176 ).subscribe(pathname => {
177 if (is18nPath(pathname)) {
178 this.document.documentElement.lang = getShortLocale(pathname.split('/')[1])
179 } else {
180 this.document.documentElement.lang = 'en'
181 }
182 })
183
173 navigationEndEvent.subscribe(e => { 184 navigationEndEvent.subscribe(e => {
174 this.hooks.runAction('action:router.navigation-end', 'common', { path: e.url }) 185 this.hooks.runAction('action:router.navigation-end', 'common', { path: e.url })
175 }) 186 })