aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/spellchecker.ts
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-08-21 08:07:32 +0530
committerLibravatar Vijay A <avijayr@protonmail.com>2021-08-21 08:55:38 +0530
commitb1cf1849f5bfa8f297f78a5ca58d797f466b3086 (patch)
tree658f3adeb740cf54021dfb6ad951649f0d539e6d /src/webview/spellchecker.ts
parentrefactor(cleanup): remove code that refers to paid subscription (diff)
downloadferdium-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.ts35
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 @@
1import { getCurrentWebContents } from '@electron/remote';
2import { SPELLCHECKER_LOCALES } from '../i18n/languages';
3import { DEFAULT_APP_SETTINGS, isMac } from '../environment';
4
5const debug = require('debug')('Ferdi:spellchecker');
6
7const webContents = getCurrentWebContents();
8const [defaultLocale] = webContents.session.getSpellCheckerLanguages();
9debug('Spellchecker default locale is', defaultLocale);
10
11export 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
17export 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}