django-tinymce: dictionary not found for language 'en'
I had a Django issue with django-tinymce throwing errors on the spell checker. Digging through the traceback revealed this error:
RuntimeError: dictionary not found for language 'en'
That’s weird, I specifically installed an English dictionary when I spawned my server. Turns out there is a naming issue.
Skip the story and jump to the solution
TinyMCE, at least the one that ships with django-tinymce includes the spellchecker plugin, and in that plugin there is a set of recognized languages and their associated language codes:
// from plugins/spellchecker/editor_plugin_src.js ed.getParam('spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr ...
I assume the ‘+’ next to English means default. At any rate, I had to make sure I wasn’t seeing things, and sure enough:
>>> import enchant >>> enchant.dict_exists('en') False
So back to the naming issue. I use Hunspell (an offshoot of MySpell) and when I installed it I was sure to set LINGUAS="en"
in my make.conf. So I made sure the English dictionary really did install.
$ hunspell -D LOADED DICTIONARY: /usr/share/myspell/en_US.aff /usr/share/myspell/en_US.dic Hunspell 1.3.2
And there’s the problem. TinyMCE is trying to load a dictionary named ‘en’, and Hunspell provides a dictionary named ‘en_US’.
Solution
cd /usr/share/myspell sudo ln -s en_US.aff en.aff sudo ln -s en_US.dic en.dic