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

Move to Chrome's fork of Hunspell #50

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7bbdcdb
Move to hunspell from Chrome 52.0.2737.0
anaisbetts Jun 1, 2016
2b51f37
Nuke the path arg
anaisbetts Jun 1, 2016
1ec2c75
Add a new API SetDictionaryToContents
anaisbetts Jun 1, 2016
c0a385e
Move to bdic file
anaisbetts Jun 1, 2016
29a24c7
Update spellchecker to new provider API
anaisbetts Jun 1, 2016
b285dd4
Update the legacy API
anaisbetts Jun 1, 2016
4dd034d
Update spec dictionaries
anaisbetts Jun 1, 2016
7a582c5
Fix casing for Linux
anaisbetts Jun 1, 2016
21b592a
Add a method to get the download URL for a dictionary
anaisbetts Jun 1, 2016
2a2756f
Get the tests running again
anaisbetts Jun 1, 2016
314f1b9
Breaking changes break shit
anaisbetts Jun 1, 2016
5a71c61
No DEPS file
anaisbetts Jun 1, 2016
3cc9139
Ignoreeeeeee
anaisbetts Jun 1, 2016
8fc59a1
string16.cc only on POSIX
anaisbetts Jun 1, 2016
7655ffa
Don't include icu
anaisbetts Jun 1, 2016
6be8fd2
Pin harder
anaisbetts Jun 1, 2016
d854efc
No idea why this is an error
anaisbetts Jun 1, 2016
e335676
Fix OS X maybe
anaisbetts Jun 1, 2016
8fffb0f
Nop harder
anaisbetts Jun 1, 2016
a10b9b9
Fix build on VS2013
anaisbetts Jun 1, 2016
bc7c24b
Fix oops typo
anaisbetts Jun 4, 2016
89ba0d3
Correctly specify SDK on OS X
anaisbetts Jul 17, 2016
846a6b3
Handle auto corrections on macOS
anaisbetts Sep 29, 2016
bd2427b
Fix dumb oopses
anaisbetts Sep 29, 2016
97449b9
I am not good.
anaisbetts Sep 29, 2016
fdf14f1
Don't double-add items
anaisbetts Sep 29, 2016
e3fd064
fix(getURLForHunspellDictionary): return correct url for some non-formed
kwonoj Jan 23, 2017
c5e5e90
Merge pull request #67 from kwonoj/feat-support-nonformed-bdict
anaisbetts Jan 23, 2017
13a0a2f
This should not be const
felixrieseberg Sep 27, 2017
c7a14a7
Merge pull request #85 from felixrieseberg/patch-1
anaisbetts Sep 27, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DS_Store
build/
/build/
node_modules/
npm-debug.log
43 changes: 43 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,30 @@
'sources': [
'src/spellchecker_hunspell.cc',
],
'include_dirs': [
'vendor/hunspell/src',
],
}],
['OS=="win"', {
'sources': [
'src/spellchecker_win.cc',
'src/transcoder_win.cc',
],
'defines': [ 'WCHAR_T_IS_UTF16' ],
}],
['OS=="linux"', {
'sources': [
'src/spellchecker_linux.cc',
'src/transcoder_posix.cc',
],
'defines': [ 'WCHAR_T_IS_UTF32' ],
}],
['OS=="mac"', {
'sources': [
'src/spellchecker_mac.mm',
'src/transcoder_posix.cc',
],
'defines': [ 'WCHAR_T_IS_UTF32' ],
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/AppKit.framework',
Expand All @@ -74,8 +80,43 @@
'msvs_guid': 'D5E8DCB2-9C61-446F-8BEE-B18CA0E0936E',
'defines': [
'HUNSPELL_STATIC',
'HUNSPELL_CHROME_CLIENT',
],
'conditions': [
['OS=="win"', {
'defines': [ 'WCHAR_T_IS_UTF16', ],
}],
['OS=="linux"', {
'defines': [ 'WCHAR_T_IS_UTF32', ],
'sources': [
'vendor/hunspell/src/base/strings/string16.cc',
]
}],
['OS=="mac"', {
'defines': [ 'WCHAR_T_IS_UTF32', ],
'sources': [
'vendor/hunspell/src/base/strings/string16.cc',
]
}],
],
'include_dirs': [
'vendor/hunspell/src',
],
'sources': [
'vendor/hunspell/src/base/base_export.h',
'vendor/hunspell/src/base/logging.h',
'vendor/hunspell/src/base/macros.h',
'vendor/hunspell/src/base/md5.cc',
'vendor/hunspell/src/base/md5.h',
'vendor/hunspell/src/base/stl_util.h',
'vendor/hunspell/src/base/strings/string_piece.cc',
'vendor/hunspell/src/base/strings/string_piece.h',
'vendor/hunspell/src/base/strings/string16.h',
'vendor/hunspell/src/build/build.h',
'vendor/hunspell/src/google/bdict_reader.cc',
'vendor/hunspell/src/google/bdict_reader.h',
'vendor/hunspell/src/google/bdict.cc',
'vendor/hunspell/src/google/bdict.h',
'vendor/hunspell/src/hunspell/affentry.cxx',
'vendor/hunspell/src/hunspell/affentry.hxx',
'vendor/hunspell/src/hunspell/affixmgr.cxx',
Expand Down Expand Up @@ -107,11 +148,13 @@
'vendor/hunspell/src/hunspell/w_char.hxx',
'vendor/hunspell/src/parsers/textparser.cxx',
'vendor/hunspell/src/parsers/textparser.hxx',

],
'direct_dependent_settings': {
'defines': [
'HUNSPELL_STATIC',
'USE_HUNSPELL',
'HUNSPELL_CHROME_CLIENT'
],
},
}
Expand Down
47 changes: 39 additions & 8 deletions lib/spellchecker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var path = require('path');
var fs = require('fs');
var bindings = require('../build/Release/spellchecker.node');

var Spellchecker = bindings.Spellchecker;
Expand All @@ -19,7 +20,17 @@ var ensureDefaultSpellCheck = function() {

var setDictionary = function(lang, dictPath) {
ensureDefaultSpellCheck();
return defaultSpellcheck.setDictionary(lang, dictPath);

var filePath = path.join(dictPath, lang.replace(/_/g, '-') + '.bdic');
var contents = null;

try {
contents = fs.readFileSync(filePath);
} catch (e) {
return false;
}

return defaultSpellcheck.setDictionary(lang, contents);
};

var isMisspelled = function() {
Expand Down Expand Up @@ -60,15 +71,34 @@ var getAvailableDictionaries = function() {

var getDictionaryPath = function() {
var dict = path.join(__dirname, '..', 'vendor', 'hunspell_dictionaries');
try {
// HACK: Special case being in an asar archive
var unpacked = dict.replace('.asar' + path.sep, '.asar.unpacked' + path.sep);
if (require('fs').statSyncNoException(unpacked)) {
dict = unpacked;
return dict;
}

var getURLForHunspellDictionary = function(lang) {
// NB: This is derived from https://code.google.com/p/chromium/codesearch#chromium/src/chrome/common/spellcheck_common.cc&sq=package:chromium&type=cs&rcl=1464736770&l=107
var defaultVersion = '-3-0';
var specialVersions = {
'tr-tr': '-4-0',
'tg-tg': '-5-0',
'en-ca': '-7-1',
'en-gb': '-7-1',
'en-us': '-7-1',
'fa-ir': '-7-0',
};

var nonFormedLangCode = ['ko', 'sh', 'sq', 'sr'];
var langCode = lang.replace(/_/g, '-').toLowerCase();

//some bdict in choromium does not follow form of language code with locale,
//formed as language only (i.e, https://src.chromium.org/viewvc/chrome/trunk/deps/third_party/hunspell_dictionaries/ko-3-0.bdic)
var language = langCode.split('-')[0];
for (var idx = 0; idx < nonFormedLangCode.length; idx++) {
if (language === nonFormedLangCode[idx]) {
langCode = nonFormedLangCode[idx];
}
} catch (error) {
}
return dict;

return "https://redirector.gvt1.com/edgedl/chrome/dict/" + langCode + (specialVersions[langCode] || defaultVersion) + ".bdic";
}

module.exports = {
Expand All @@ -79,5 +109,6 @@ module.exports = {
checkSpelling: checkSpelling,
getAvailableDictionaries: getAvailableDictionaries,
getCorrectionsForMisspelling: getCorrectionsForMisspelling,
getURLForHunspellDictionary: getURLForHunspellDictionary,
Spellchecker: Spellchecker
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"main": "./lib/spellchecker.js",
"name": "spellchecker",
"description": "Bindings to native spellchecker",
"version": "3.3.1",
"version": "4.0.0",
"licenses": [
{
"type": "MIT",
Expand Down
Binary file added spec/dictionaries/de-DE.bdic
Binary file not shown.
Loading