mirror of https://github.com/Ombi-app/Ombi
parent
3a0040031c
commit
a8dd23d29f
@ -0,0 +1,18 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
|
||||
@Injectable()
|
||||
export class StorageService {
|
||||
|
||||
public get(key: string): string {
|
||||
return localStorage.getItem(key);
|
||||
}
|
||||
|
||||
public save(key: string, value: string): void {
|
||||
this.remove(key);
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
|
||||
public remove(key: string) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<div class="small-middle-container" *ngIf="username">
|
||||
<h3 [translate]="'UserPreferences.Welcome'" [translateParams]="{username: username}"></h3>
|
||||
|
||||
<hr>
|
||||
<div>
|
||||
<mat-form-field>
|
||||
<mat-label [translate]="'UserPreferences.OmbiLanguage'"></mat-label>
|
||||
<mat-select [(value)]="selectedLang" (selectionChange)="languageSelected();">
|
||||
<mat-option *ngFor="let lang of availableLanguages" [value]="lang.value">
|
||||
{{lang.display}}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,5 @@
|
||||
.small-middle-container{
|
||||
margin: auto;
|
||||
margin-top: 3%;
|
||||
width: 80%;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { AuthService } from "../../../auth/auth.service";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { AvailableLanguages, ILanguage } from "./user-preference.constants";
|
||||
import { StorageService } from "../../../shared/storage/storage-service";
|
||||
|
||||
@Component({
|
||||
templateUrl: "./user-preference.component.html",
|
||||
styleUrls: ["./user-preference.component.scss"],
|
||||
})
|
||||
export class UserPreferenceComponent implements OnInit {
|
||||
|
||||
public username: string;
|
||||
public selectedLang: string;
|
||||
public availableLanguages = AvailableLanguages;
|
||||
|
||||
constructor(private authService: AuthService,
|
||||
private readonly translate: TranslateService,
|
||||
private storage: StorageService) { }
|
||||
|
||||
public ngOnInit(): void {
|
||||
const user = this.authService.claims();
|
||||
if(user.name) {
|
||||
this.username = user.name;
|
||||
}
|
||||
const selectedLang = this.storage.get("Language");
|
||||
if(selectedLang) {
|
||||
this.selectedLang = selectedLang;
|
||||
}
|
||||
}
|
||||
|
||||
public languageSelected() {
|
||||
this.storage.save("Language", this.selectedLang);
|
||||
this.translate.use(this.selectedLang);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
export const AvailableLanguages: ILanguage[] = [
|
||||
{ display: 'English', value: 'en' },
|
||||
{ display: 'Français', value: 'fr' },
|
||||
{ display: 'Dansk', value: 'da' },
|
||||
{ display: 'Deutsch', value: 'de' },
|
||||
{ display: 'Italiano', value: 'it' },
|
||||
{ display: 'Español', value: 'es' },
|
||||
{ display: 'Nederlands', value: 'nl' },
|
||||
{ display: 'Norsk', value: 'no' },
|
||||
{ display: 'Português (Brasil)', value: 'pt' },
|
||||
{ display: 'Polski', value: 'pl' },
|
||||
{ display: 'Svenska', value: 'sv' },
|
||||
];
|
||||
|
||||
export interface ILanguage {
|
||||
display: string;
|
||||
value: string;
|
||||
}
|
Loading…
Reference in new issue