Sublime Forum

[SOLVED] Hunspell dictionary isn’t working for a non-English language

#1

I use Sublime Text on a Linux OS. It has hunspell-1.4.1-r1 with packages for English and Russian languages myspell-en-20160201 and myspell-ru-20150711-r1. I’ve made a subdirectory under ~/.config/sublime-text-3/Packages called Hunspell_dicts and symlinked the *.dic and *.aff files into it. I also found a combined dictionary, that comes, e.g. as an addon to Firefox, and made symlinks for it, too. Here’s the contents of Hunspell_dicts:

$ ls -l ~/.config/sublime-text-3/Packages/Hunspell_dicts/
total 8.0K
lrwxrwxrwx 1 dtr dtr 28 Aug 22 18:39 en_GB.aff -> /usr/share/myspell/en_GB.aff
lrwxrwxrwx 1 dtr dtr 28 Aug 22 18:39 en_GB.dic -> /usr/share/myspell/en_GB.dic
lrwxrwxrwx 1 dtr dtr 71 Aug 22 18:21 ru-English.aff -> /home/dtr/.ff/extensions/ruendict@russia.ru/dictionaries/ru-English.aff
lrwxrwxrwx 1 dtr dtr 71 Aug 22 18:21 ru-English.dic -> /home/dtr/.ff/extensions/ruendict@russia.ru/dictionaries/ru-English.dic
lrwxrwxrwx 1 dtr dtr 28 Aug 22 18:39 ru_RU.aff -> /usr/share/myspell/ru_RU.aff
lrwxrwxrwx 1 dtr dtr 28 Aug 22 18:27 ru_RU.dic -> /usr/share/myspell/ru_RU.dic

In the …/Packages/User/Preferences.sublime-settings I’ve changed lines related to dictionary and spell checking to

"dictionary": "Packages/Hunspell_dicts/ru_RU.dic",
"spell_check": true,

But words typed in Cyrillic remain highlighted as wrong. Except for those typed in ALL CAPS, for some reason… I’ve tried to restart Sublime Text, switch to other dictionaries in View → Dictionaries – I see all three dicts in Hunspell_dicts submenu plus en_GB and en_US in ‘Language – English’ submenu, that is always present, though I don’t have such a subfolder under Packages/ – nothing helps.

At the same time incorrectly spelled words in English are highlighted properly for both combined and en_GB dictionaries (both the internal and symlinked), so I think it may be related to UTF support.

I use Sublime Text build 3114, purchased it the last month, invoice number 805137.

0 Likes

#2

You could try to use the dictionaries from the Dictionary package.

0 Likes

#3

Thanks, the Dictionary package worked well, but I was more interested in the combined version.

The problem was that dictionaries must be in UTF-8 encoding in order for Sublime Text to read them. The actual encoding can be found in the first lines of the .aff files:

$ head -n1 ru-English.aff 
SET WINDOWS-1251

The ru_RU dictionary I took from the OS was in KOI8-R, while the one I picked from Firefox was in CP1251, as one could guess from the command above. I converted the latter with iconv, because internal Sublime Text commands, I mean reopening with CP1251 and saving with UTF-8, didn’t work for some reason. Though I’ve seen the Cyrillic appearing instead of garbage in the files while reopening them. Anyway, here’s the command I suggest to anyone finding this later:

$ cd ~/.config/sublime-text-3/Packages/Hunspell_dicts
$ for ext in aff dic; do \
      iconv -f cp1251 -t utf-8 ru-English.$ext >/tmp/t; \
      mv /tmp/t ru-English.$ext; \
  done

The addon I took the combined dictionary from is https://addons.mozilla.org/en-us/firefox/addon/english-russian-dict/ — but remember to convert it!

1 Like