diff options
-rw-r--r-- | src/config.ts | 1 | ||||
-rw-r--r-- | src/helpers/i18n-helpers.ts | 56 | ||||
-rw-r--r-- | src/stores/AppStore.js | 47 |
3 files changed, 38 insertions, 66 deletions
diff --git a/src/config.ts b/src/config.ts index fe9145021..82ce131f9 100644 --- a/src/config.ts +++ b/src/config.ts | |||
@@ -198,7 +198,6 @@ export const DEFAULT_APP_SETTINGS = { | |||
198 | spellcheckerLanguage: 'en-us', | 198 | spellcheckerLanguage: 'en-us', |
199 | darkMode: false, | 199 | darkMode: false, |
200 | splitMode: false, | 200 | splitMode: false, |
201 | locale: '', | ||
202 | fallbackLocale: 'en-US', | 201 | fallbackLocale: 'en-US', |
203 | beta: false, | 202 | beta: false, |
204 | isAppMuted: false, | 203 | isAppMuted: false, |
diff --git a/src/helpers/i18n-helpers.ts b/src/helpers/i18n-helpers.ts index ec7dc8e98..e6c66c7d3 100644 --- a/src/helpers/i18n-helpers.ts +++ b/src/helpers/i18n-helpers.ts | |||
@@ -1,52 +1,44 @@ | |||
1 | export function getLocale({ | 1 | export function getLocale({ locale, locales, fallbackLocale }) { |
2 | locale, locales, defaultLocale, fallbackLocale, | 2 | if (!locale) { |
3 | }) { | 3 | return fallbackLocale; |
4 | let localeStr = locale; | 4 | } |
5 | if (locales[locale] === undefined) { | 5 | |
6 | if (!locales[locale]) { | ||
6 | let localeFuzzy: string | undefined; | 7 | let localeFuzzy: string | undefined; |
7 | for (const localStr of Object.keys(locales)) { | 8 | for (const localStr of Object.keys(locales)) { |
8 | if (locales && Object.hasOwnProperty.call(locales, localStr) && locale.slice(0, 2) === localStr.slice(0, 2)) { | 9 | if (locale.slice(0, 2) === localStr.slice(0, 2)) { |
9 | localeFuzzy = localStr; | 10 | localeFuzzy = localStr; |
10 | } | 11 | } |
11 | } | 12 | } |
12 | 13 | ||
13 | if (localeFuzzy !== undefined) { | 14 | if (localeFuzzy) { |
14 | localeStr = localeFuzzy; | 15 | return localeFuzzy; |
15 | } | 16 | } |
16 | } | 17 | } |
17 | 18 | ||
18 | if (locales[localeStr] === undefined) { | 19 | return locale; |
19 | localeStr = defaultLocale; | ||
20 | } | ||
21 | |||
22 | if (!localeStr) { | ||
23 | localeStr = fallbackLocale; | ||
24 | } | ||
25 | |||
26 | return localeStr; | ||
27 | } | 20 | } |
28 | 21 | ||
29 | export function getSelectOptions({ | 22 | export function getSelectOptions({ |
30 | locales, resetToDefaultText = '', automaticDetectionText = '', sort = true, | 23 | locales, |
24 | resetToDefaultText = '', | ||
25 | automaticDetectionText = '', | ||
26 | sort = true, | ||
31 | }) { | 27 | }) { |
32 | const options: object[] = []; | 28 | const options: object[] = []; |
33 | 29 | ||
34 | if (resetToDefaultText) { | 30 | if (resetToDefaultText) { |
35 | options.push( | 31 | options.push({ |
36 | { | 32 | value: '', |
37 | value: '', | 33 | label: resetToDefaultText, |
38 | label: resetToDefaultText, | 34 | }); |
39 | }, | ||
40 | ); | ||
41 | } | 35 | } |
42 | 36 | ||
43 | if (automaticDetectionText) { | 37 | if (automaticDetectionText) { |
44 | options.push( | 38 | options.push({ |
45 | { | 39 | value: 'automatic', |
46 | value: 'automatic', | 40 | label: automaticDetectionText, |
47 | label: automaticDetectionText, | 41 | }); |
48 | }, | ||
49 | ); | ||
50 | } | 42 | } |
51 | 43 | ||
52 | options.push({ | 44 | options.push({ |
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 3d9d2b551..a86a54c6d 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -17,16 +17,8 @@ import { readJsonSync } from 'fs-extra'; | |||
17 | import Store from './lib/Store'; | 17 | import Store from './lib/Store'; |
18 | import Request from './lib/Request'; | 18 | import Request from './lib/Request'; |
19 | import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; | 19 | import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; |
20 | import { | 20 | import { isMac, electronVersion, osRelease } from '../environment'; |
21 | isMac, | 21 | import { ferdiVersion, userDataPath, ferdiLocale } from '../environment-remote'; |
22 | electronVersion, | ||
23 | osRelease, | ||
24 | } from '../environment'; | ||
25 | import { | ||
26 | ferdiVersion, | ||
27 | userDataPath, | ||
28 | ferdiLocale, | ||
29 | } from '../environment-remote'; | ||
30 | import locales from '../i18n/translations'; | 22 | import locales from '../i18n/translations'; |
31 | import { getLocale } from '../helpers/i18n-helpers'; | 23 | import { getLocale } from '../helpers/i18n-helpers'; |
32 | 24 | ||
@@ -41,8 +33,6 @@ const debug = require('debug')('Ferdi:AppStore'); | |||
41 | 33 | ||
42 | const mainWindow = getCurrentWindow(); | 34 | const mainWindow = getCurrentWindow(); |
43 | 35 | ||
44 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; | ||
45 | |||
46 | const executablePath = isMac ? remoteProcess.execPath : process.execPath; | 36 | const executablePath = isMac ? remoteProcess.execPath : process.execPath; |
47 | const autoLauncher = new AutoLaunch({ | 37 | const autoLauncher = new AutoLaunch({ |
48 | name: 'Ferdi', | 38 | name: 'Ferdi', |
@@ -80,9 +70,9 @@ export default class AppStore extends Store { | |||
80 | 70 | ||
81 | @observable timeOfflineStart; | 71 | @observable timeOfflineStart; |
82 | 72 | ||
83 | @observable updateStatus = null; | 73 | @observable updateStatus = ''; |
84 | 74 | ||
85 | @observable locale = defaultLocale; | 75 | @observable locale = ferdiLocale; |
86 | 76 | ||
87 | @observable isSystemMuteOverridden = false; | 77 | @observable isSystemMuteOverridden = false; |
88 | 78 | ||
@@ -408,7 +398,7 @@ export default class AppStore extends Store { | |||
408 | } | 398 | } |
409 | 399 | ||
410 | @action _resetUpdateStatus() { | 400 | @action _resetUpdateStatus() { |
411 | this.updateStatus = null; | 401 | this.updateStatus = ''; |
412 | } | 402 | } |
413 | 403 | ||
414 | @action _healthCheck() { | 404 | @action _healthCheck() { |
@@ -480,23 +470,13 @@ export default class AppStore extends Store { | |||
480 | } | 470 | } |
481 | 471 | ||
482 | _setLocale() { | 472 | _setLocale() { |
483 | let locale; | 473 | if (this.stores.user.isLoggedIn && this.stores.user.data.locale) { |
484 | if (this.stores.user.isLoggedIn) { | 474 | this.locale = this.stores.user.data.locale; |
485 | locale = this.stores.user.data.locale; | 475 | } else if (!this.locale) { |
486 | } | ||
487 | |||
488 | if ( | ||
489 | locale && | ||
490 | Object.prototype.hasOwnProperty.call(locales, locale) && | ||
491 | locale !== this.locale | ||
492 | ) { | ||
493 | this.locale = locale; | ||
494 | } else if (!locale) { | ||
495 | this.locale = this._getDefaultLocale(); | 476 | this.locale = this._getDefaultLocale(); |
496 | } | 477 | } |
497 | 478 | ||
498 | moment.locale(this.locale); | 479 | moment.locale(this.locale); |
499 | |||
500 | debug(`Set locale to "${this.locale}"`); | 480 | debug(`Set locale to "${this.locale}"`); |
501 | } | 481 | } |
502 | 482 | ||
@@ -504,7 +484,6 @@ export default class AppStore extends Store { | |||
504 | return getLocale({ | 484 | return getLocale({ |
505 | locale: ferdiLocale, | 485 | locale: ferdiLocale, |
506 | locales, | 486 | locales, |
507 | defaultLocale, | ||
508 | fallbackLocale: DEFAULT_APP_SETTINGS.fallbackLocale, | 487 | fallbackLocale: DEFAULT_APP_SETTINGS.fallbackLocale, |
509 | }); | 488 | }); |
510 | } | 489 | } |
@@ -523,10 +502,12 @@ export default class AppStore extends Store { | |||
523 | _handleFullScreen() { | 502 | _handleFullScreen() { |
524 | const body = document.querySelector('body'); | 503 | const body = document.querySelector('body'); |
525 | 504 | ||
526 | if (this.isFullScreen) { | 505 | if (body) { |
527 | body.classList.add('isFullScreen'); | 506 | if (this.isFullScreen) { |
528 | } else { | 507 | body.classList.add('isFullScreen'); |
529 | body.classList.remove('isFullScreen'); | 508 | } else { |
509 | body.classList.remove('isFullScreen'); | ||
510 | } | ||
530 | } | 511 | } |
531 | } | 512 | } |
532 | 513 | ||