diff options
Diffstat (limited to 'client/src/app/app.component.ts')
-rw-r--r-- | client/src/app/app.component.ts | 17 |
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 @@ | |||
1 | import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core' | 1 | import { Component, OnInit, ViewChild, AfterViewInit, Inject } from '@angular/core' |
2 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' | 2 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' |
3 | import { Event, GuardsCheckStart, NavigationEnd, Router, Scroll } from '@angular/router' | 3 | import { Event, GuardsCheckStart, NavigationEnd, Router, Scroll } from '@angular/router' |
4 | import { AuthService, RedirectService, ServerService, ThemeService } from '@app/core' | 4 | import { AuthService, RedirectService, ServerService, ThemeService } from '@app/core' |
5 | import { is18nPath } from '../../../shared/models/i18n' | 5 | import { is18nPath, getShortLocale } from '../../../shared/models/i18n' |
6 | import { ScreenService } from '@app/shared/misc/screen.service' | 6 | import { ScreenService } from '@app/shared/misc/screen.service' |
7 | import { filter, map, pairwise, first } from 'rxjs/operators' | 7 | import { filter, map, pairwise, first } from 'rxjs/operators' |
8 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' | 8 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' |
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | 9 | import { I18n } from '@ngx-translate/i18n-polyfill' |
10 | import { PlatformLocation, ViewportScroller } from '@angular/common' | 10 | import { PlatformLocation, ViewportScroller, DOCUMENT } from '@angular/common' |
11 | import { PluginService } from '@app/core/plugins/plugin.service' | 11 | import { PluginService } from '@app/core/plugins/plugin.service' |
12 | import { HooksService } from '@app/core/plugins/hooks.service' | 12 | import { HooksService } from '@app/core/plugins/hooks.service' |
13 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | 13 | import { 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 | }) |