diff options
author | Vijay A <avijayr@protonmail.com> | 2021-08-21 08:07:32 +0530 |
---|---|---|
committer | Vijay A <avijayr@protonmail.com> | 2021-08-21 08:55:38 +0530 |
commit | b1cf1849f5bfa8f297f78a5ca58d797f466b3086 (patch) | |
tree | 658f3adeb740cf54021dfb6ad951649f0d539e6d /src/webview/spellchecker.ts | |
parent | refactor(cleanup): remove code that refers to paid subscription (diff) | |
download | ferdium-app-b1cf1849f5bfa8f297f78a5ca58d797f466b3086.tar.gz ferdium-app-b1cf1849f5bfa8f297f78a5ca58d797f466b3086.tar.zst ferdium-app-b1cf1849f5bfa8f297f78a5ca58d797f466b3086.zip |
chore: typescript conversion
Diffstat (limited to 'src/webview/spellchecker.ts')
-rw-r--r-- | src/webview/spellchecker.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/webview/spellchecker.ts b/src/webview/spellchecker.ts new file mode 100644 index 000000000..aa9a2350f --- /dev/null +++ b/src/webview/spellchecker.ts | |||
@@ -0,0 +1,35 @@ | |||
1 | import { getCurrentWebContents } from '@electron/remote'; | ||
2 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | ||
3 | import { DEFAULT_APP_SETTINGS, isMac } from '../environment'; | ||
4 | |||
5 | const debug = require('debug')('Ferdi:spellchecker'); | ||
6 | |||
7 | const webContents = getCurrentWebContents(); | ||
8 | const [defaultLocale] = webContents.session.getSpellCheckerLanguages(); | ||
9 | debug('Spellchecker default locale is', defaultLocale); | ||
10 | |||
11 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { | ||
12 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); | ||
13 | |||
14 | return locales.length >= 1 ? locales[0] : null; | ||
15 | } | ||
16 | |||
17 | export function switchDict(locale: string) { | ||
18 | if (isMac) { | ||
19 | debug('Ignoring dictionary changes on macOS'); | ||
20 | return; | ||
21 | } | ||
22 | |||
23 | debug('Setting spellchecker locale to', locale); | ||
24 | |||
25 | const locales: string[] = []; | ||
26 | |||
27 | const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); | ||
28 | if (foundLocale) { | ||
29 | locales.push(foundLocale); | ||
30 | } | ||
31 | |||
32 | locales.push(defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale); | ||
33 | |||
34 | webContents.session.setSpellCheckerLanguages(locales); | ||
35 | } | ||