cfinke / Typo.js

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

Can't use Romance languages #57

Closed writemonkey closed 2 years ago

writemonkey commented 7 years ago

Hello, I managed to integrate typo.js into my nw.js + Codemirror project just fine, but can't use it with Romance languages (Italian, Spanish, French ...). When trying to load them, there is a lengthy pause an then my app crashes.

Is there a way to make those dictionaries to work?

Thanks for the great library,

i.

whyteks commented 4 years ago

I see this issue is old, but maybe as good a place to comment as any.

In an attempt to get https://github.com/hackmdio/codimd to show Spanish spelling errors, I could not get https://github.com/wooorm/dictionaries/tree/master/dictionaries/es to work at all.

I do not know anything at all about parsing the Hunspell SFX lines, but one thing seems sure;

parseRuleCodes() is broken here as with the first SFX line, we fail badly: https://github.com/wooorm/dictionaries/blob/master/dictionaries/es/index.aff#L112

    SFX A r ción/S ar

Please take a look at https://github.com/cfinke/Typo.js/blob/master/typo/typo.js#L534 I think this is wrong: we have "FLAG" in this.flags and so we do not in fact match any if stanza here and therefore the function returns undefined, resulting in an exception when we try to access .length of undefined in

https://github.com/cfinke/Typo.js/blob/master/typo/typo.js#L327

Are you supposed to reset this.flags at some point?

I tried returning something by default, adding

return textCodes.split("");

at Line 549 and now the dictionary works.

@cfinke I hope that may be of some use to you.

Best regards.

cfinke commented 2 years ago

Thanks for the heads up; I've fixed this in 14f97490f59cd19b9838c8e8dee5170971fc5995 by adding support for UTF-8 flags.

Running textCodes.split("") would indeed work for this specific dictionary, but if it actually used any UTF-8 flags, it would have led to some unexpected behavior.