Skip to content

Commit 81d8d1d

Browse files
committed
Merge pull request RocketChat#128 from RocketChat/improvements/huspell-dicts
Improvements/huspell dicts
2 parents 4c1bf07 + 4903021 commit 81d8d1d

File tree

9 files changed

+161626
-28
lines changed

9 files changed

+161626
-28
lines changed

app/scripts/preload.js

+44-28
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ var webContents = remote.getCurrentWebContents();
7474
var Menu = remote.require('menu');
7575
var menu = new Menu();
7676

77+
var path = remote.require('path');
78+
7779
// set the initial context menu so that a context menu exists even before spellcheck is called
7880
var getTemplate = function() {
7981
return [
@@ -111,6 +113,7 @@ let languagesMenu;
111113
let checker;
112114
const enabledDictionaries = [];
113115
let availableDictionaries = [];
116+
let dictionariesPath;
114117

115118
if (localStorage.getItem('spellcheckerDictionaries')) {
116119
let spellcheckerDictionaries = JSON.parse(localStorage.getItem('spellcheckerDictionaries'));
@@ -119,8 +122,12 @@ if (localStorage.getItem('spellcheckerDictionaries')) {
119122
}
120123
}
121124

122-
if (localStorage.getItem('userLanguage') && enabledDictionaries.indexOf(localStorage.getItem('userLanguage')) === -1) {
123-
enabledDictionaries.push(localStorage.getItem('userLanguage'));
125+
if (enabledDictionaries.length === 0) {
126+
if (localStorage.getItem('userLanguage')) {
127+
enabledDictionaries.push(localStorage.getItem('userLanguage'));
128+
}
129+
130+
enabledDictionaries.push(navigator.language.replace('-', '_'));
124131
}
125132

126133
const saveEnabledDictionaries = function() {
@@ -138,7 +145,7 @@ const isCorrect = function(text) {
138145
return;
139146
}
140147

141-
checker.setDictionary(enabledDictionary);
148+
checker.setDictionary(enabledDictionary, dictionariesPath);
142149
if (!checker.isMisspelled(text)) {
143150
isCorrect = true;
144151
}
@@ -156,16 +163,17 @@ const getCorrections = function(text) {
156163
return;
157164
}
158165

159-
checker.setDictionary(enabledDictionary);
166+
checker.setDictionary(enabledDictionary, dictionariesPath);
160167
const languageCorrections = checker.getCorrectionsForMisspelling(text);
161168
if (languageCorrections.length > 0) {
162169
allCorrections.push(languageCorrections);
163170
}
164171
});
165172

166173
// Get the size of biggest array
167-
const length = allCorrections.length === 0 ? 0 : allCorrections.reduce(function(a, b) {
168-
return Math.max(a.length || a, b.length || b);
174+
let length = 0;
175+
allCorrections.forEach(function(items) {
176+
length = Math.max(length, items.length);
169177
});
170178

171179
// Merge all arrays until the size of the biggest array
@@ -196,30 +204,38 @@ try {
196204

197205
availableDictionaries = checker.getAvailableDictionaries();
198206

199-
if (availableDictionaries.length > 0) {
200-
languagesMenu = {
201-
label: 'Spelling languages',
202-
submenu: []
203-
};
207+
if (availableDictionaries.length === 0) {
208+
dictionariesPath = path.join(remote.app.getAppPath(), '../dictionaries');
209+
console.log('dictionariesPath', dictionariesPath);
210+
availableDictionaries = [
211+
'en_US',
212+
'es_ES',
213+
'pt_BR'
214+
];
215+
}
204216

205-
availableDictionaries.forEach((dictionary) => {
206-
const menu = {
207-
label: dictionary,
208-
type: 'checkbox',
209-
checked: enabledDictionaries.indexOf(dictionary) > -1,
210-
click: function(menuItem) {
211-
menu.checked = menuItem.checked;
212-
if (menuItem.checked) {
213-
enabledDictionaries.push(dictionary);
214-
} else {
215-
enabledDictionaries.splice(enabledDictionaries.indexOf(dictionary), 1);
216-
}
217-
saveEnabledDictionaries();
217+
languagesMenu = {
218+
label: 'Spelling languages',
219+
submenu: []
220+
};
221+
222+
availableDictionaries.forEach((dictionary) => {
223+
const menu = {
224+
label: dictionary,
225+
type: 'checkbox',
226+
checked: enabledDictionaries.indexOf(dictionary) > -1,
227+
click: function(menuItem) {
228+
menu.checked = menuItem.checked;
229+
if (menuItem.checked) {
230+
enabledDictionaries.push(dictionary);
231+
} else {
232+
enabledDictionaries.splice(enabledDictionaries.indexOf(dictionary), 1);
218233
}
219-
};
220-
languagesMenu.submenu.push(menu);
221-
});
222-
}
234+
saveEnabledDictionaries();
235+
}
236+
};
237+
languagesMenu.submenu.push(menu);
238+
});
223239

224240
webFrame.setSpellCheckProvider('', false, {
225241
spellCheck: function(text) {

dictionaries/en_US.aff

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
SET UTF8
2+
TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ'
3+
ICONV 1
4+
ICONV ’ '
5+
NOSUGGEST !
6+
7+
# ordinal numbers
8+
COMPOUNDMIN 1
9+
# only in compounds: 1th, 2th, 3th
10+
ONLYINCOMPOUND c
11+
# compound rules:
12+
# 1. [0-9]*1[0-9]th (10th, 11th, 12th, 56714th, etc.)
13+
# 2. [0-9]*[02-9](1st|2nd|3rd|[4-9]th) (21st, 22nd, 123rd, 1234th, etc.)
14+
COMPOUNDRULE 2
15+
COMPOUNDRULE n*1t
16+
COMPOUNDRULE n*mp
17+
WORDCHARS 0123456789
18+
19+
PFX A Y 1
20+
PFX A 0 re .
21+
22+
PFX I Y 1
23+
PFX I 0 in .
24+
25+
PFX U Y 1
26+
PFX U 0 un .
27+
28+
PFX C Y 1
29+
PFX C 0 de .
30+
31+
PFX E Y 1
32+
PFX E 0 dis .
33+
34+
PFX F Y 1
35+
PFX F 0 con .
36+
37+
PFX K Y 1
38+
PFX K 0 pro .
39+
40+
SFX V N 2
41+
SFX V e ive e
42+
SFX V 0 ive [^e]
43+
44+
SFX N Y 3
45+
SFX N e ion e
46+
SFX N y ication y
47+
SFX N 0 en [^ey]
48+
49+
SFX X Y 3
50+
SFX X e ions e
51+
SFX X y ications y
52+
SFX X 0 ens [^ey]
53+
54+
SFX H N 2
55+
SFX H y ieth y
56+
SFX H 0 th [^y]
57+
58+
SFX Y Y 1
59+
SFX Y 0 ly .
60+
61+
SFX G Y 2
62+
SFX G e ing e
63+
SFX G 0 ing [^e]
64+
65+
SFX J Y 2
66+
SFX J e ings e
67+
SFX J 0 ings [^e]
68+
69+
SFX D Y 4
70+
SFX D 0 d e
71+
SFX D y ied [^aeiou]y
72+
SFX D 0 ed [^ey]
73+
SFX D 0 ed [aeiou]y
74+
75+
SFX T N 4
76+
SFX T 0 st e
77+
SFX T y iest [^aeiou]y
78+
SFX T 0 est [aeiou]y
79+
SFX T 0 est [^ey]
80+
81+
SFX R Y 4
82+
SFX R 0 r e
83+
SFX R y ier [^aeiou]y
84+
SFX R 0 er [aeiou]y
85+
SFX R 0 er [^ey]
86+
87+
SFX Z Y 4
88+
SFX Z 0 rs e
89+
SFX Z y iers [^aeiou]y
90+
SFX Z 0 ers [aeiou]y
91+
SFX Z 0 ers [^ey]
92+
93+
SFX S Y 4
94+
SFX S y ies [^aeiou]y
95+
SFX S 0 s [aeiou]y
96+
SFX S 0 es [sxzh]
97+
SFX S 0 s [^sxzhy]
98+
99+
SFX P Y 3
100+
SFX P y iness [^aeiou]y
101+
SFX P 0 ness [aeiou]y
102+
SFX P 0 ness [^y]
103+
104+
SFX M Y 1
105+
SFX M 0 's .
106+
107+
SFX B Y 3
108+
SFX B 0 able [^aeiou]
109+
SFX B 0 able ee
110+
SFX B e able [^aeiou]e
111+
112+
SFX L Y 1
113+
SFX L 0 ment .
114+
115+
REP 90
116+
REP a ei
117+
REP ei a
118+
REP a ey
119+
REP ey a
120+
REP ai ie
121+
REP ie ai
122+
REP alot a_lot
123+
REP are air
124+
REP are ear
125+
REP are eir
126+
REP air are
127+
REP air ere
128+
REP ere air
129+
REP ere ear
130+
REP ere eir
131+
REP ear are
132+
REP ear air
133+
REP ear ere
134+
REP eir are
135+
REP eir ere
136+
REP ch te
137+
REP te ch
138+
REP ch ti
139+
REP ti ch
140+
REP ch tu
141+
REP tu ch
142+
REP ch s
143+
REP s ch
144+
REP ch k
145+
REP k ch
146+
REP f ph
147+
REP ph f
148+
REP gh f
149+
REP f gh
150+
REP i igh
151+
REP igh i
152+
REP i uy
153+
REP uy i
154+
REP i ee
155+
REP ee i
156+
REP j di
157+
REP di j
158+
REP j gg
159+
REP gg j
160+
REP j ge
161+
REP ge j
162+
REP s ti
163+
REP ti s
164+
REP s ci
165+
REP ci s
166+
REP k cc
167+
REP cc k
168+
REP k qu
169+
REP qu k
170+
REP kw qu
171+
REP o eau
172+
REP eau o
173+
REP o ew
174+
REP ew o
175+
REP oo ew
176+
REP ew oo
177+
REP ew ui
178+
REP ui ew
179+
REP oo ui
180+
REP ui oo
181+
REP ew u
182+
REP u ew
183+
REP oo u
184+
REP u oo
185+
REP u oe
186+
REP oe u
187+
REP u ieu
188+
REP ieu u
189+
REP ue ew
190+
REP ew ue
191+
REP uff ough
192+
REP oo ieu
193+
REP ieu oo
194+
REP ier ear
195+
REP ear ier
196+
REP ear air
197+
REP air ear
198+
REP w qu
199+
REP qu w
200+
REP z ss
201+
REP ss z
202+
REP shun tion
203+
REP shun sion
204+
REP shun cion
205+
REP size cise

0 commit comments

Comments
 (0)