Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 7db13e7

Browse files
author
Chris Marsh
committed
expose setDictionary
1 parent 543a4e8 commit 7db13e7

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/spellchecker.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ var bindings = require('bindings')('spellchecker.node');
44
var Spellchecker = bindings.Spellchecker;
55

66
var defaultSpellcheck = null;
7-
var ensureDefaultSpellCheck = function() {
8-
if (defaultSpellcheck) return;
97

8+
var setDictionary = function(lang, dictPath) {
109
defaultSpellcheck = new Spellchecker();
11-
1210
// NB: Windows 8 uses *dashes* to set the language (i.e. en-US), so if we fail
1311
// to set the language, try the Windows 8 way
14-
var dict = getDictionaryPath();
15-
if (!defaultSpellcheck.setDictionary('en_US', dict)) {
16-
defaultSpellcheck.setDictionary('en-US', dict);
12+
lang = lang.replace('_', '-');
13+
if (!defaultSpellcheck.setDictionary(lang, dictPath)) {
14+
lang = lang.replace('-', '_');
15+
defaultSpellcheck.setDictionary(lang, dictPath);
16+
}
17+
};
18+
19+
var ensureDefaultSpellCheck = function() {
20+
if (defaultSpellcheck) {
21+
return;
1722
}
23+
setDictionary('en_US', getDictionaryPath());
1824
};
1925

2026
var isMisspelled = function() {
@@ -55,6 +61,7 @@ var getDictionaryPath = function() {
5561
}
5662

5763
module.exports = {
64+
setDictionary: setDictionary,
5865
add: add,
5966
isMisspelled: isMisspelled,
6067
getAvailableDictionaries: getAvailableDictionaries,

spec/spellchecker-spec.coffee

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ describe "SpellChecker", ->
4040
expect(Array.isArray(dictionaries)).toBe true
4141

4242
# Dictionaries do not appear to be available on AppVeyor
43-
unless process.platform is 'win32' and process.env.CI
43+
unless process.platform is 'win32' and (process.env.CI or process.env.SPELLCHECKER_PREFER_HUNSPELL)
4444
expect(dictionaries.length).toBeGreaterThan 0
4545

4646
for dictionary in dictionaries.length
4747
expect(typeof dictionary).toBe 'string'
4848
expect(diction.length).toBeGreaterThan 0
49+
50+
describe ".setDictionary(lang, dictDirectory)", ->
51+
it "sets the spell checker's language, and dictionary directory", ->
52+
awesome = true
53+
expect(awesome).toBe true

0 commit comments

Comments
 (0)