Skip to content

Commit ca90ce0

Browse files
committed
Close RocketChat#162; Every word typed is highlighted as being misspelled
1 parent fc75ced commit ca90ce0

File tree

1 file changed

+53
-8
lines changed

1 file changed

+53
-8
lines changed

app/scripts/preload.js

+53-8
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,6 @@ if (localStorage.getItem('spellcheckerDictionaries')) {
122122
}
123123
}
124124

125-
if (enabledDictionaries.length === 0) {
126-
if (localStorage.getItem('userLanguage')) {
127-
enabledDictionaries.push(localStorage.getItem('userLanguage'));
128-
}
129-
130-
enabledDictionaries.push(navigator.language.replace('-', '_'));
131-
}
132-
133125
const saveEnabledDictionaries = function() {
134126
localStorage.setItem('spellcheckerDictionaries', JSON.stringify(enabledDictionaries));
135127
};
@@ -213,6 +205,59 @@ try {
213205
];
214206
}
215207

208+
availableDictionaries = availableDictionaries.sort(function(a, b) {
209+
if (a > b) {
210+
return 1;
211+
}
212+
if (a < b) {
213+
return -1;
214+
}
215+
return 0;
216+
});
217+
218+
for (var i = enabledDictionaries.length - 1; i >= 0; i--) {
219+
if (availableDictionaries.indexOf(enabledDictionaries[i]) === -1) {
220+
enabledDictionaries.splice(i, 1);
221+
}
222+
}
223+
224+
if (enabledDictionaries.length === 0) {
225+
if (localStorage.getItem('userLanguage')) {
226+
let userLanguage = localStorage.getItem('userLanguage').replace('-', '_');
227+
if (availableDictionaries.indexOf(userLanguage) > -1) {
228+
enabledDictionaries.push(userLanguage);
229+
}
230+
if (userLanguage.indexOf('_') > -1) {
231+
userLanguage = userLanguage.split('_')[0];
232+
if (availableDictionaries.indexOf(userLanguage) > -1) {
233+
enabledDictionaries.push(userLanguage);
234+
}
235+
}
236+
}
237+
238+
let navigatorLanguage = navigator.language.replace('-', '_');
239+
if (availableDictionaries.indexOf(navigatorLanguage) > -1) {
240+
enabledDictionaries.push(navigatorLanguage);
241+
}
242+
if (navigatorLanguage.indexOf('_') > -1) {
243+
navigatorLanguage = navigatorLanguage.split('_')[0];
244+
if (availableDictionaries.indexOf(navigatorLanguage) > -1) {
245+
enabledDictionaries.push(navigatorLanguage);
246+
}
247+
}
248+
}
249+
250+
if (enabledDictionaries.length === 0) {
251+
let defaultLanguage = 'en_US';
252+
if (availableDictionaries.indexOf(defaultLanguage) > -1) {
253+
enabledDictionaries.push(defaultLanguage);
254+
}
255+
defaultLanguage = defaultLanguage.split('_')[0];
256+
if (availableDictionaries.indexOf(defaultLanguage) > -1) {
257+
enabledDictionaries.push(defaultLanguage);
258+
}
259+
}
260+
216261
languagesMenu = {
217262
label: 'Spelling languages',
218263
submenu: []

0 commit comments

Comments
 (0)