added locale backup + en support

This commit is contained in:
_Bastler
2021-03-26 10:17:28 +01:00
parent a9fd56efc6
commit 34755be840
16 changed files with 2724 additions and 1039 deletions
+20 -31
View File
@@ -1,24 +1,16 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import {
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot
} from '@angular/router';
import { AuthService } from '../services/auth.service';
import {Injectable} from '@angular/core';
import {Router} from '@angular/router';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
import {AuthService} from '../services/auth.service';
@Injectable({
providedIn: 'root'
})
export class AuthUpdateGuard implements CanActivate {
constructor(private authService: AuthService) { }
constructor(private authService: AuthService) {}
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
this.authService.getAuth().catch(function (error) { });
this.authService.getAuth().catch(function(error) {});
return true;
}
}
@@ -27,15 +19,14 @@ export class AuthUpdateGuard implements CanActivate {
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) { }
constructor(private authService: AuthService, private router: Router) {}
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const that = this;
return this.authService.getAuth().then(response => {
return true;
}).catch(function (error) {
that.router.navigateByUrl('/unavailable');
return false;
}).catch(function(error) {
return that.router.parseUrl('/unavailable');
});
}
}
@@ -44,19 +35,18 @@ export class AuthGuard implements CanActivate {
providedIn: 'root'
})
export class AuthenticatedGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) { }
constructor(private authService: AuthService, private router: Router) {}
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const that = this;
return this.authService.getAuth().then((data: any) => {
if (!data.authenticated) {
if(!data.authenticated) {
this.router.navigateByUrl('/login');
return false;
}
return true;
}).catch(function (error) {
that.router.navigateByUrl('/unavailable');
return false;
}).catch(function(error) {
return that.router.parseUrl('/unavailable');
});
}
}
@@ -65,19 +55,18 @@ export class AuthenticatedGuard implements CanActivate {
providedIn: 'root'
})
export class AnonymousGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) { }
constructor(private authService: AuthService, private router: Router) {}
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const that = this;
return this.authService.getAuth().then((data: any) => {
if (data.authenticated) {
if(data.authenticated) {
this.router.navigateByUrl('/account/info');
return false;
}
return true;
}).catch(function (error) {
that.router.navigateByUrl('/unavailable');
return false;
}).catch(function(error) {
return that.router.parseUrl('/unavailable');
});
}
@@ -0,0 +1,3 @@
.text-warning {
color: darkred;
}
+6 -3
View File
@@ -2,7 +2,8 @@ import {Component, OnInit} from '@angular/core';
@Component({
selector: 'app-imprint',
templateUrl: './general.imprint.html'
templateUrl: './general.imprint.html',
styleUrls: ['./general.component.scss']
})
export class ImprintComponent implements OnInit {
@@ -16,7 +17,8 @@ export class ImprintComponent implements OnInit {
@Component({
selector: 'app-privacy-policy',
templateUrl: './general.privacy-policy.html'
templateUrl: './general.privacy-policy.html',
styleUrls: ['./general.component.scss']
})
export class PrivacyPolicyComponent implements OnInit {
@@ -30,7 +32,8 @@ export class PrivacyPolicyComponent implements OnInit {
@Component({
selector: 'app-terms-of-service',
templateUrl: './general.terms-of-service.html'
templateUrl: './general.terms-of-service.html',
styleUrls: ['./general.component.scss']
})
export class TermsOfServiceComponent implements OnInit {
@@ -8,4 +8,12 @@
{{'service-unavailable.text' | i18n}}
</p>
</mat-card-content>
<mat-card-actions>
<a mat-raised-button color="primary" (click)="retry()">
{{'service-unavailable.retry' | i18n}}
</a>
<a mat-raised-button href="https://wiki.bstly.de/help#Support">
{{'service-unavailable.support' | i18n}}
</a>
</mat-card-actions>
</mat-card>
@@ -10,6 +10,6 @@ mat-card {
padding: 0;
}
mat-card-content {
padding: 16px;
mat-card-content, mat-card-actions {
padding: 16px !important;
}
@@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import {Component, OnInit} from '@angular/core';
import { Location } from '@angular/common'
@Component({
selector: 'app-unavailable',
@@ -7,9 +8,14 @@ import { Component, OnInit } from '@angular/core';
})
export class UnavailableComponent implements OnInit {
constructor() { }
constructor(
private location: Location) {}
ngOnInit(): void {
}
retry() {
this.location.back();
}
}
+17 -10
View File
@@ -1,18 +1,18 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import { environment } from '../../environments/environment';
import {environment} from '../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class I18nService {
locale: string;
locales : any = ["de-informal"];
locale: string = "de-informal";
locales: any = ["de-informal"];
i18n: any;
constructor(private http: HttpClient) {
}
getLocales() {
@@ -28,29 +28,36 @@ export class I18nService {
}
async fetch() {
let browserLocale = navigator.language;
if(browserLocale.indexOf("-") != -1) {
browserLocale = browserLocale.split("-")[0];
}
let locale = localStorage.getItem("bstly.locale") || browserLocale || this.locales[0];
let locale = localStorage.getItem("bstly.locale") || browserLocale || this.locales[0];
if(locale == 'de') {
locale = 'de-informal';
}
this.locales = await this.http.get(environment.apiUrl + "/i18n").toPromise();
try {
this.locales = await this.http.get(environment.apiUrl + "/i18n").toPromise();
} catch(e) {
console.debug("fallback to default locales");
}
if(this.locales.indexOf(locale) == -1) {
locale = this.locales[0];
}
this.setLocale(locale);
this.i18n = await this.http.get(environment.apiUrl + "/i18n/" + locale).toPromise();
try {
this.i18n = await this.http.get(environment.apiUrl + "/i18n/" + locale).toPromise();
} catch(e) {
this.i18n = await this.http.get("/assets/i18n/" + locale + ".json").toPromise();
console.debug("fallback to default locale");
}
}
get(key, args: string[]): string {