Skip to main content

Adding new dictionary to the spellchecker

By default in Linux, when installing the Enchant extension, only the en_US dictionary is made available.

In Windows there are no dictionaries included by default.

It is recommended to install the dictionary you require prior to installation. This document will take you through how to install/add new dictionaries to your system.

Linux

To check the available dictionary run the following command

hunspell -D

The output will be something like this; listing all the available dictionaries you can use

SEARCH PATH:
.::/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/root/.openoffice.org/3/user/wordbook:.openoffice.org2/user/wordbook:.openoffice.org2.0/user/wordbook:Library/Spelling:/opt/openoffice.org/basis3.0/share/dict/ooo:/usr/lib/openoffice.org/basis3.0/share/dict/ooo:/opt/openoffice.org2.4/share/dict/ooo:/usr/lib/openoffice.org2.4/share/dict/ooo:/opt/openoffice.org2.3/share/dict/ooo:/usr/lib/openoffice.org2.3/share/dict/ooo:/opt/openoffice.org2.2/share/dict/ooo:/usr/lib/openoffice.org2.2/share/dict/ooo:/opt/openoffice.org2.1/share/dict/ooo:/usr/lib/openoffice.org2.1/share/dict/ooo:/opt/openoffice.org2.0/share/dict/ooo:/usr/lib/openoffice.org2.0/share/dict/ooo
AVAILABLE DICTIONARIES (path is not mandatory for -d option):
/usr/share/myspell/en_US

To check all the available dictionaries that you can install run

$ yum search hunspell-
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: d36uatko69830t.cloudfront.net
* epel: mirrors.coreix.net
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
=================================================================== N/S matched: hunspell- ===================================================================
hunspell-af.noarch : Afrikaans hunspell dictionary
hunspell-ak.noarch : Akan hunspell dictionaries
hunspell-am.noarch : Amharic hunspell dictionaries
hunspell-ar.noarch : Arabic hunspell dictionaries
hunspell-as.noarch : Assamese hunspell dictionaries
…..

Find the right dictionary package and run yum install to add a new dictionary into your system.

$ yum install -y hunspell-en-GB
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: d36uatko69830t.cloudfront.net
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
Resolving Dependencies
--> Running transaction check
---> Package hunspell-en-GB.noarch 0:0.20121024-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================
Installing:
hunspell-en-GB noarch 0.20121024-6.el7 base 239 k

Transaction Summary
==============================================================================================================================================================
Install 1 Package

Total download size: 239 k
Installed size: 543 k
Downloading packages:
hunspell-en-GB-0.20121024-6.el7.noarch.rpm | 239 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : hunspell-en-GB-0.20121024-6.el7.noarch 1/1
Verifying : hunspell-en-GB-0.20121024-6.el7.noarch 1/1

Installed:
hunspell-en-GB.noarch 0:0.20121024-6.el7

If you now check the list of dictionary that are available to use, you should see en_Gb added to your list

$ hunspell -D
SEARCH PATH:
.::/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/root/.openoffice.org/3/user/wordbook:.openoffice.org2/user/wordbook:.openoffice.org2.0/user/wordbook:Library/Spelling:/opt/openoffice.org/basis3.0/share/dict/ooo:/usr/lib/openoffice.org/basis3.0/share/dict/ooo:/opt/openoffice.org2.4/share/dict/ooo:/usr/lib/openoffice.org2.4/share/dict/ooo:/opt/openoffice.org2.3/share/dict/ooo:/usr/lib/openoffice.org2.3/share/dict/ooo:/opt/openoffice.org2.2/share/dict/ooo:/usr/lib/openoffice.org2.2/share/dict/ooo:/opt/openoffice.org2.1/share/dict/ooo:/usr/lib/openoffice.org2.1/share/dict/ooo:/opt/openoffice.org2.0/share/dict/ooo:/usr/lib/openoffice.org2.0/share/dict/ooo
AVAILABLE DICTIONARIES (path is not mandatory for -d option):
/usr/share/myspell/en_US
/usr/share/myspell/en_GB
LOADED DICTIONARY:
/usr/share/myspell/en_GB.aff
/usr/share/myspell/en_GB.dic

Windows

Adding a new dictionary in windows is a simple 3 step process.

  1. Download the latest dictionary from the link specified in the hunspell website. The recommended option is from Libreoffice. The file extensions you should look for are .aff and .dic under the applicable language directory.
  2. Create a sub folder in your php installation directory, share\enchant\myspell. For example if your php installation directory is C:\php then you have to create a directory structure C:\php\share\enchant\myspell
  3. Copy the downloaded files to the myspell directory created in the above step.