aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/spellchecker.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2019-09-27 13:56:49 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2019-09-27 13:56:49 +0200
commit9180318200dc2b398bc2ec248f9ff8fa3f035fbb (patch)
tree2e080ccc65efa5acab5fb4c2a1e3ef269709623b /src/webview/spellchecker.js
parentFix spellchecker integration (diff)
downloadferdium-app-9180318200dc2b398bc2ec248f9ff8fa3f035fbb.tar.gz
ferdium-app-9180318200dc2b398bc2ec248f9ff8fa3f035fbb.tar.zst
ferdium-app-9180318200dc2b398bc2ec248f9ff8fa3f035fbb.zip
Fix spellchecker
Diffstat (limited to 'src/webview/spellchecker.js')
-rw-r--r--src/webview/spellchecker.js32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js
index 64575753f..d7bb983dc 100644
--- a/src/webview/spellchecker.js
+++ b/src/webview/spellchecker.js
@@ -1,6 +1,5 @@
1import { webFrame } from 'electron'; 1import { webFrame } from 'electron';
2import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; 2import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell';
3import { ENVIRONMENT } from 'hunspell-asm';
4import path from 'path'; 3import path from 'path';
5import { readFileSync } from 'fs'; 4import { readFileSync } from 'fs';
6 5
@@ -14,6 +13,8 @@ let currentDict;
14let _isEnabled = false; 13let _isEnabled = false;
15let attached; 14let attached;
16 15
16const DEFAULT_LOCALE = 'en-us';
17
17async function loadDictionary(locale) { 18async function loadDictionary(locale) {
18 try { 19 try {
19 const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); 20 const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`);
@@ -24,7 +25,7 @@ async function loadDictionary(locale) {
24 } 25 }
25} 26}
26 27
27export async function switchDict(locale) { 28export async function switchDict(locale = DEFAULT_LOCALE) {
28 try { 29 try {
29 debug('Trying to load dictionary', locale); 30 debug('Trying to load dictionary', locale);
30 31
@@ -55,13 +56,23 @@ export async function switchDict(locale) {
55 } 56 }
56} 57}
57 58
58export default async function initialize(languageCode = 'en-us') { 59export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) {
60 const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase());
61
62 if (locales.length >= 1) {
63 return locales[0];
64 }
65
66 return null;
67}
68
69export default async function initialize(languageCode = DEFAULT_LOCALE) {
59 try { 70 try {
60 provider = new SpellCheckerProvider(); 71 provider = new SpellCheckerProvider();
61 const locale = languageCode.toLowerCase(); 72 const locale = getSpellcheckerLocaleByFuzzyIdentifier(languageCode);
62 73
63 debug('Init spellchecker'); 74 debug('Init spellchecker');
64 await provider.initialize({ environment: ENVIRONMENT.NODE }); 75 await provider.initialize();
65 76
66 debug('Attaching spellcheck provider'); 77 debug('Attaching spellcheck provider');
67 attached = await attachSpellCheckProvider(provider); 78 attached = await attachSpellCheckProvider(provider);
@@ -69,7 +80,6 @@ export default async function initialize(languageCode = 'en-us') {
69 debug('Available spellchecker dictionaries', provider.availableDictionaries); 80 debug('Available spellchecker dictionaries', provider.availableDictionaries);
70 81
71 attached.switchLanguage(locale); 82 attached.switchLanguage(locale);
72 console.log('seas oida', attached, provider);
73 83
74 return provider; 84 return provider;
75 } catch (err) { 85 } catch (err) {
@@ -89,13 +99,3 @@ export function disable() {
89 currentDict = null; 99 currentDict = null;
90 } 100 }
91} 101}
92
93export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) {
94 const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase());
95
96 if (locales.length >= 1) {
97 return locales[0];
98 }
99
100 return null;
101}