fix i18n iframe

This commit is contained in:
_Bastler 2022-03-20 14:00:25 +01:00
parent bb857d58cc
commit 95c4be6536
2 changed files with 11 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment'; import { environment } from '../../environments/environment';
import { MatPaginatorIntl } from '@angular/material/paginator'; import { MatPaginatorIntl } from '@angular/material/paginator';
import { Subject, firstValueFrom } from 'rxjs'; import { Subject, firstValueFrom } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -13,9 +14,8 @@ export class I18nService {
locales: any = [ "de-informal" ]; locales: any = [ "de-informal" ];
i18n: any; i18n: any;
constructor(private http: HttpClient) { constructor(private http: HttpClient,
private route: ActivatedRoute) { }
}
getLocales() { getLocales() {
return this.locales; return this.locales;
@ -41,7 +41,9 @@ export class I18nService {
let locale = browserLocale || this.locales[ 0 ]; let locale = browserLocale || this.locales[ 0 ];
try { try {
locale = localStorage.getItem("bstly.locale") || locale; locale = localStorage.getItem("bstly.locale") || locale;
} catch { } } catch {
locale = window.location.search.split("locale=")[ 1 ];
}
if (locale == 'de') { if (locale == 'de') {
locale = 'de-informal'; locale = 'de-informal';
@ -59,7 +61,6 @@ export class I18nService {
} }
this.setLocale(locale); this.setLocale(locale);
} }
get(key, args: string[]): string { get(key, args: string[]): string {

View File

@ -8,7 +8,7 @@ import { fromEvent } from 'rxjs';
import { AuthService } from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import { I18nService } from '../../services/i18n.service'; import { I18nService } from '../../services/i18n.service';
import { ProfileService } from '../../services/profile.service'; import { ProfileService } from '../../services/profile.service';
import { MatSidenav } from '@angular/material/sidenav'; import { Location } from '@angular/common';
@Component({ @Component({
selector: 'app-main', selector: 'app-main',
@ -36,6 +36,7 @@ export class MainComponent {
private router: Router, private router: Router,
private iconRegistry: MatIconRegistry, private iconRegistry: MatIconRegistry,
private sanitizer: DomSanitizer, private sanitizer: DomSanitizer,
private location: Location,
private _adapter: DateAdapter<any>) { private _adapter: DateAdapter<any>) {
iconRegistry.addSvgIcon('logo', sanitizer.bypassSecurityTrustResourceUrl('assets/icons/logo.svg')); iconRegistry.addSvgIcon('logo', sanitizer.bypassSecurityTrustResourceUrl('assets/icons/logo.svg'));
} }
@ -71,7 +72,9 @@ export class MainComponent {
setLocale(locale) { setLocale(locale) {
try { try {
localStorage.setItem("bstly.locale", locale); localStorage.setItem("bstly.locale", locale);
} catch { } } catch {
this.location.replaceState(window.location.pathname, 'locale=' + locale);
}
if (this.auth && this.auth.authenticated) { if (this.auth && this.auth.authenticated) {
this.profileService.getField("locale").subscribe({ this.profileService.getField("locale").subscribe({