blob: e7ef102e95650d41823df05dfbd8a226ada9bed7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import {
remote,
} from 'electron';
import { SPELLCHECKER_LOCALES } from '../i18n/languages';
import { isMac } from '../environment';
const debug = require('debug')('Franz:spellchecker');
const webContents = remote.getCurrentWebContents();
const [defaultLocale] = webContents.session.getSpellCheckerLanguages();
debug('Spellchecker default locale is', defaultLocale);
export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) {
const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase());
if (locales.length >= 1) {
return locales[0];
}
return null;
}
export function switchDict(locale) {
if (isMac) {
debug('Ignoring dictionary changes on macOS');
return;
}
debug('Setting spellchecker locale to', locale);
const locales = [];
const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale);
if (foundLocale) {
locales.push(foundLocale);
}
locales.push(defaultLocale, 'de');
webContents.session.setSpellCheckerLanguages(locales);
}
|