Skip to content

Commit

Permalink
FIXED: default to en locale if preferred locale is not available fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
warpdesign authored Aug 26, 2020
1 parent 9b32cec commit 31e41c2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/locale/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ i18next.on('languageChanged', () => {
ipcRenderer.send('languageChanged', i18next.t('APP_MENUS', { returnObjects: true }));
});

export { i18next };
const languageList = Object.keys(locales);

export { i18next, languageList };
17 changes: 7 additions & 10 deletions src/state/settingsState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { observable, action } from "mobx";
import { remote } from 'electron';
import { JSObject } from "../components/Log";
import { i18next } from '../locale/i18n';
import { i18next, languageList } from '../locale/i18n';
import { isMojave, isWin, isMac, defaultFolder } from '../utils/platform';

const { systemPreferences } = remote;
Expand Down Expand Up @@ -71,19 +71,15 @@ export class SettingsState {
lang = remote.app.getLocale();
}

// Note: it seems i18next may not always
// have cached all languages, even though it will correctly work.
// Comment this out for now since it prevents locale other than English
// from working
// if (i18next.languages.indexOf(lang) < 0) {
// lang = 'en';
// }
// fallback to English if preferred language
// isn't available
if (languageList.indexOf(lang) < 0) {
lang = 'en';
}

// finally set requested language
i18next.changeLanguage(lang);

console.log('setting language to', i18next.language);

this.lang = i18next.language;
}

Expand Down Expand Up @@ -118,6 +114,7 @@ export class SettingsState {
@action
loadAndUpgradeSettings(): JSObject {
let settings = this.getParam(APP_STORAGE_KEY);

// no settings set: first time the app is run
if (settings === null) {
settings = this.getDefaultSettings();
Expand Down

0 comments on commit 31e41c2

Please sign in to comment.