cfinke / Typo.js

A client-side JavaScript spellchecker that uses Hunspell-style dictionaries.
Other
496 stars 110 forks source link

Multiple dictionaries? #37

Open JuanCaicedo opened 8 years ago

JuanCaicedo commented 8 years ago

I see in the docs that Typo needs to be initialized with a dictionary code. Would it be feasible to enhance this so that it can load multiple dictionaries? If that's not impossible and sounds useful, I would be willing to help :)

cfinke commented 8 years ago

It's not impossible. Is the use case for bi-lingual people that would be writing in multiple languages? Or is it for loading multiple dictionaries in a single language, like the main English dictionary plus a slang dictionary?

It might be simpler to just instantiate multiple Typo objects, one for each dictionary.

JuanCaicedo commented 8 years ago

Personally I have a Spanish and English dictionary, but I think this would serve both use cases.

Currently I have a prototype where I instantiated two Typo object, though what I have to do is do a lookup in both and then concat the results. It would be nice if I could make one call and get a single array of suggestions from both dictionaries. Also, that step could remove duplicates.

akonsu commented 7 years ago

This feature is what I was looking for too. My use case is a language dictionary and a dictionary with technical terms for this language.

richardtallent commented 7 years ago

I ended up manually adding words to dictionaryTable from a Javascript array. That did the trick for my limited needs, which simply involve handling some industry-specific lingo.

zguillen commented 7 years ago

@richardtallent I need to do something similar (letting users add a term to the dictionary while editing a file) and I tried the same approach you did, something like: typo.dictionaryTable[word] = null;

but I put a breakpoint in typo.js's 'checkExact' function that runs right after I add the new word and its not there. Did this work for you?

zguillen commented 7 years ago

oh, nevermind...I just happened to be testing with a word that although was correctly being added to dictionaryTable it would fail the spell checking for other reasons (the word was zoe1234zoe or something, and the combo of letters and numbers is what failed the check, not the word).