Added ability to select language in settings

Fixed locale support so that it actually works at runtime

Removed unused library
This commit is contained in:
Isaac Grynsztein
2020-03-15 14:52:07 -04:00
parent ebd0a419df
commit c7885e8726
6 changed files with 793 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { PostsService } from 'app/posts.services';
import { isoLangs } from './locales_list';
import { MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'app-settings',
@@ -7,12 +9,15 @@ import { PostsService } from 'app/posts.services';
styleUrls: ['./settings.component.scss']
})
export class SettingsComponent implements OnInit {
all_locales = isoLangs;
supported_locales = ['en', 'es'];
initialLocale = localStorage.getItem('locale');
initial_config = null;
new_config = null
loading_config = false;
constructor(private postsService: PostsService) { }
constructor(private postsService: PostsService, private snackBar: MatSnackBar) { }
ngOnInit() {
this.getConfig();
@@ -46,4 +51,16 @@ export class SettingsComponent implements OnInit {
})
}
localeSelectChanged(new_val) {
localStorage.setItem('locale', new_val);
this.openSnackBar('Language successfully changed! Reload to update the page.')
}
// snackbar helper
public openSnackBar(message: string, action: string = '') {
this.snackBar.open(message, action, {
duration: 2000,
});
}
}