Add language selection in settings (#75)

* Add language selection in settings

* Removed comment

* Mapping Locale-Language saved as key-value instead of list of objects

* Remove comment

* Revert supported locales array
This commit is contained in:
Costantini Matteo 2018-04-25 05:25:31 +02:00 committed by Kyle Spearrin
parent 4d015568f5
commit 6bf0821ca6
7 changed files with 43 additions and 12 deletions

3
package-lock.json generated
View File

@ -4223,7 +4223,8 @@
"jsbn": { "jsbn": {
"version": "0.1.1", "version": "0.1.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"json-schema": { "json-schema": {
"version": "0.2.3", "version": "0.2.3",

View File

@ -42,6 +42,14 @@
</div> </div>
<small class="help-block">{{'disableFaviconDesc' | i18n}}</small> <small class="help-block">{{'disableFaviconDesc' | i18n}}</small>
</div> </div>
<div class="form-group">
<label for="locale">{{'language' | i18n}}</label>
<select id="locale" name="Locale" [(ngModel)]="locale"
(change)="saveLocale()">
<option *ngFor="let o of locales" [ngValue]="o.locale">{{o.language}}</option>
</select>
<small class="help-block">{{'languageDesc' | i18n}}</small>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -15,6 +15,8 @@ import { StorageService } from 'jslib/abstractions/storage.service';
import { ConstantsService } from 'jslib/services/constants.service'; import { ConstantsService } from 'jslib/services/constants.service';
import { SupportedTranslationLocales } from '../../services/i18n.service';
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',
templateUrl: 'settings.component.html', templateUrl: 'settings.component.html',
@ -24,6 +26,8 @@ export class SettingsComponent implements OnInit {
lockOption: number = null; lockOption: number = null;
disableGa: boolean = false; disableGa: boolean = false;
disableFavicons: boolean = false; disableFavicons: boolean = false;
locales: any[];
locale: string;
constructor(private analytics: Angulartics2, private toasterService: ToasterService, constructor(private analytics: Angulartics2, private toasterService: ToasterService,
private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService,
@ -43,11 +47,17 @@ export class SettingsComponent implements OnInit {
{ name: i18nService.t('onRestart'), value: -1 }, { name: i18nService.t('onRestart'), value: -1 },
{ name: i18nService.t('never'), value: null }, { name: i18nService.t('never'), value: null },
]; ];
this.locales = [ { locale: null, language: 'Default' } ];
Object.keys(SupportedTranslationLocales).forEach((localId) => {
this.locales.push({locale: localId, language: i18nService.t(localId)});
});
} }
async ngOnInit() { async ngOnInit() {
this.lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey); this.lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey); this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
this.locale = await this.storageService.get<string>('locale');
const disableGa = await this.storageService.get<boolean>(ConstantsService.disableGaKey); const disableGa = await this.storageService.get<boolean>(ConstantsService.disableGaKey);
const disableGaByDefault = this.platformUtilsService.isFirefox() || this.platformUtilsService.isMacAppStore(); const disableGaByDefault = this.platformUtilsService.isFirefox() || this.platformUtilsService.isMacAppStore();
@ -79,4 +89,8 @@ export class SettingsComponent implements OnInit {
const status = enabled ? 'Enabled' : 'Disabled'; const status = enabled ? 'Enabled' : 'Disabled';
this.analytics.eventTrack.next({ action: `${status} ${name}` }); this.analytics.eventTrack.next({ action: `${status} ${name}` });
} }
async saveLocale() {
await this.storageService.save('locale', this.locale);
}
} }

View File

@ -110,7 +110,7 @@ environmentService.setUrlsFromStorage().then(() => {
export function initFactory(): Function { export function initFactory(): Function {
return async () => { return async () => {
await i18nService.init(); await i18nService.init(await storageService.get<string>('locale'));
await authService.init(); await authService.init();
const htmlEl = window.document.documentElement; const htmlEl = window.document.documentElement;
htmlEl.classList.add('os_' + platformUtilsService.getDeviceString()); htmlEl.classList.add('os_' + platformUtilsService.getDeviceString());

View File

@ -770,6 +770,12 @@
"disableFaviconDesc": { "disableFaviconDesc": {
"message": "Website Icons provide a recognizable image next to each login item in your vault." "message": "Website Icons provide a recognizable image next to each login item in your vault."
}, },
"language": {
"message": "Language"
},
"languageDesc": {
"message": "Change language. Require restart."
},
"copy": { "copy": {
"message": "Copy", "message": "Copy",
"description": "Copy to clipboard" "description": "Copy to clipboard"

View File

@ -62,15 +62,17 @@ export class Main {
} }
bootstrap() { bootstrap() {
this.windowMain.init().then(async () => { this.storageService.get<string>('locale').then(async (locale) => {
await this.i18nService.init(app.getLocale()); this.windowMain.init().then(async () => {
this.messagingMain.init(); await this.i18nService.init(locale !== null ? locale : app.getLocale());
this.menuMain.init(); this.messagingMain.init();
this.powerMonitorMain.init(); this.menuMain.init();
await this.updaterMain.init(); this.powerMonitorMain.init();
}, (e: any) => { await this.updaterMain.init();
// tslint:disable-next-line }, (e: any) => {
console.error(e); // tslint:disable-next-line
console.error(e);
});
}); });
} }
} }

View File

@ -4,7 +4,7 @@ import * as path from 'path';
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service'; import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service';
// First locale is the default (English) // First locale is the default (English)
const SupportedTranslationLocales = [ export const SupportedTranslationLocales = [
'en', 'cs', 'da', 'de', 'es', 'et', 'fi', 'fr', 'hr', 'hu', 'id', 'it', 'ja', 'en', 'cs', 'da', 'de', 'es', 'et', 'fi', 'fr', 'hr', 'hu', 'id', 'it', 'ja',
'nb', 'nl', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sk', 'sv', 'tr', 'uk', 'vi', 'nb', 'nl', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sk', 'sv', 'tr', 'uk', 'vi',
'zh-CN', 'zh-TW', 'zh-CN', 'zh-TW',