diff options
-rw-r--r-- | package-lock.json | 43 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 32 |
3 files changed, 33 insertions, 44 deletions
diff --git a/package-lock.json b/package-lock.json index e670c2a03..b0cc72ec7 100644 --- a/package-lock.json +++ b/package-lock.json | |||
@@ -7190,12 +7190,11 @@ | |||
7190 | } | 7190 | } |
7191 | }, | 7191 | }, |
7192 | "electron-hunspell": { | 7192 | "electron-hunspell": { |
7193 | "version": "1.0.0-beta.7", | 7193 | "version": "1.0.0", |
7194 | "resolved": "https://registry.npmjs.org/electron-hunspell/-/electron-hunspell-1.0.0-beta.7.tgz", | 7194 | "resolved": "https://registry.npmjs.org/electron-hunspell/-/electron-hunspell-1.0.0.tgz", |
7195 | "integrity": "sha512-BByCXqU8sZbuzyoxKcBYjycp8ORiqjeYZd2OT8RNjVW+XGPmZkHewXUu4tUa1IXW6ij6IqojV5kr+xhYKLN1DA==", | 7195 | "integrity": "sha512-egyioCtGkkNMOYdKBrZsva63JxbPmNjmQVFCZCcmr+uIUs6et6OUvqd6ac9/ujuchiEPDrTfF9gdR9+lPbVyPA==", |
7196 | "requires": { | 7196 | "requires": { |
7197 | "hunspell-asm": "^2.0.0", | 7197 | "hunspell-asm": "^4.0.0" |
7198 | "tslib": "1.9.3" | ||
7199 | } | 7198 | } |
7200 | }, | 7199 | }, |
7201 | "electron-is-dev": { | 7200 | "electron-is-dev": { |
@@ -11504,32 +11503,22 @@ | |||
11504 | } | 11503 | } |
11505 | }, | 11504 | }, |
11506 | "hunspell-asm": { | 11505 | "hunspell-asm": { |
11507 | "version": "2.0.0", | 11506 | "version": "4.0.0", |
11508 | "resolved": "https://registry.npmjs.org/hunspell-asm/-/hunspell-asm-2.0.0.tgz", | 11507 | "resolved": "https://registry.npmjs.org/hunspell-asm/-/hunspell-asm-4.0.0.tgz", |
11509 | "integrity": "sha512-FMIUBpy+bRREFAvC63RcYEK9U6+FdlEojGSVsvMTpuZ2CekYyUBwEfG4+ExIQOQyEN0U6f1MoVgrFqvgPNSA2g==", | 11508 | "integrity": "sha512-EcNwMx0Byq1JHMZiuATmqpMk41bOo+NH4yD5xJ3H0X403MoDBory3zri2lJzYSGj+z/6Bqr3EZn24syCjZoY1w==", |
11510 | "requires": { | 11509 | "requires": { |
11511 | "emscripten-wasm-loader": "^2.2.3", | 11510 | "emscripten-wasm-loader": "^3.0.3", |
11512 | "nanoid": "^2.0.1", | 11511 | "nanoid": "^2.1.1" |
11513 | "tslib": "^1.9.3", | ||
11514 | "unixify": "^1.0.0" | ||
11515 | }, | 11512 | }, |
11516 | "dependencies": { | 11513 | "dependencies": { |
11517 | "emscripten-wasm-loader": { | 11514 | "emscripten-wasm-loader": { |
11518 | "version": "2.2.3", | 11515 | "version": "3.0.3", |
11519 | "resolved": "https://registry.npmjs.org/emscripten-wasm-loader/-/emscripten-wasm-loader-2.2.3.tgz", | 11516 | "resolved": "https://registry.npmjs.org/emscripten-wasm-loader/-/emscripten-wasm-loader-3.0.3.tgz", |
11520 | "integrity": "sha512-//gI0afvtVnY7smttrPOW/BM+pTJLmdIcXAQV3fgRdQ0o6wm2vdSI0kjLYVOeo/rbtRsGgVuMLu6fT+O//EfaA==", | 11517 | "integrity": "sha512-fyq2maBt5LOou27LEBlL5H6G04BxgSamXkvmMsAuIT6rd8ioH4BxNQhuyl6jVPeODh6U8Wk1BoFZxzHpg3o8wA==", |
11521 | "requires": { | 11518 | "requires": { |
11522 | "getroot": "^1.0.0", | 11519 | "getroot": "^1.0.0", |
11523 | "nanoid": "^1.3.4", | 11520 | "nanoid": "^2.0.3", |
11524 | "tslib": "^1.9.3", | ||
11525 | "unixify": "^1.0.0" | 11521 | "unixify": "^1.0.0" |
11526 | }, | ||
11527 | "dependencies": { | ||
11528 | "nanoid": { | ||
11529 | "version": "1.3.4", | ||
11530 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.3.4.tgz", | ||
11531 | "integrity": "sha512-4ug4BsuHxiVHoRUe1ud6rUFT3WUMmjXt1W0quL0CviZQANdan7D8kqN5/maw53hmAApY/jfzMRkC57BNNs60ZQ==" | ||
11532 | } | ||
11533 | } | 11522 | } |
11534 | } | 11523 | } |
11535 | } | 11524 | } |
@@ -14525,9 +14514,9 @@ | |||
14525 | "integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==" | 14514 | "integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==" |
14526 | }, | 14515 | }, |
14527 | "nanoid": { | 14516 | "nanoid": { |
14528 | "version": "2.0.3", | 14517 | "version": "2.1.1", |
14529 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.0.3.tgz", | 14518 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.1.tgz", |
14530 | "integrity": "sha512-NbaoqdhIYmY6FXDRB4eYtDVC9Z9eCbn8TyaiC16LNKtpPv/aqa0tOPD8y6gNE4yUNnaZ7LLhYtXOev/6+cBtfw==" | 14519 | "integrity": "sha512-0YbJdaL4JFoejIOoawgLcYValFGJ2iyUuVDIWL3g8Es87SSOWFbWdRUMV3VMSiyPs3SQ3QxCIxFX00q5DLkMCw==" |
14531 | }, | 14520 | }, |
14532 | "nanomatch": { | 14521 | "nanomatch": { |
14533 | "version": "1.2.13", | 14522 | "version": "1.2.13", |
diff --git a/package.json b/package.json index 2814df2ab..09874bc59 100644 --- a/package.json +++ b/package.json | |||
@@ -48,7 +48,7 @@ | |||
48 | "du": "^0.1.0", | 48 | "du": "^0.1.0", |
49 | "electron-dl": "1.12.0", | 49 | "electron-dl": "1.12.0", |
50 | "electron-fetch": "1.3.0", | 50 | "electron-fetch": "1.3.0", |
51 | "electron-hunspell": "1.0.0-beta.7", | 51 | "electron-hunspell": "1.0.0", |
52 | "electron-is-dev": "1.0.1", | 52 | "electron-is-dev": "1.0.1", |
53 | "electron-react-titlebar": "0.8.1", | 53 | "electron-react-titlebar": "0.8.1", |
54 | "electron-updater": "4.0.6", | 54 | "electron-updater": "4.0.6", |
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 @@ | |||
1 | import { webFrame } from 'electron'; | 1 | import { webFrame } from 'electron'; |
2 | import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; | 2 | import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; |
3 | import { ENVIRONMENT } from 'hunspell-asm'; | ||
4 | import path from 'path'; | 3 | import path from 'path'; |
5 | import { readFileSync } from 'fs'; | 4 | import { readFileSync } from 'fs'; |
6 | 5 | ||
@@ -14,6 +13,8 @@ let currentDict; | |||
14 | let _isEnabled = false; | 13 | let _isEnabled = false; |
15 | let attached; | 14 | let attached; |
16 | 15 | ||
16 | const DEFAULT_LOCALE = 'en-us'; | ||
17 | |||
17 | async function loadDictionary(locale) { | 18 | async 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 | ||
27 | export async function switchDict(locale) { | 28 | export 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 | ||
58 | export default async function initialize(languageCode = 'en-us') { | 59 | export 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 | |||
69 | export 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 | |||
93 | export 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 | } | ||