mirror of
https://github.com/bitwarden/desktop.git
synced 2025-01-22 21:11:28 +01:00
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:
parent
4d015568f5
commit
6bf0821ca6
3
package-lock.json
generated
3
package-lock.json
generated
@ -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",
|
||||||
|
@ -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>
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
|
@ -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"
|
||||||
|
@ -62,8 +62,9 @@ export class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bootstrap() {
|
bootstrap() {
|
||||||
|
this.storageService.get<string>('locale').then(async (locale) => {
|
||||||
this.windowMain.init().then(async () => {
|
this.windowMain.init().then(async () => {
|
||||||
await this.i18nService.init(app.getLocale());
|
await this.i18nService.init(locale !== null ? locale : app.getLocale());
|
||||||
this.messagingMain.init();
|
this.messagingMain.init();
|
||||||
this.menuMain.init();
|
this.menuMain.init();
|
||||||
this.powerMonitorMain.init();
|
this.powerMonitorMain.init();
|
||||||
@ -72,6 +73,7 @@ export class Main {
|
|||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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',
|
||||||
|
Loading…
Reference in New Issue
Block a user