dictionaries
Collection of normalized and installable hunspell dictionaries.
Contents
- What is this?
- When should I use this?
- Install
- Use
- List of dictionaries
- Examples
- Types
- Contribute
- License
What is this?
This monorepo is a bunch of scripts that crawls dictionaries from several sources, normalizes them, and packs them so that they can each be installed and used in one single way. Dictionaries are not maintained here but they are usable from here.
When should I use this?
You can particularly use the packages here as a programmer when integrating with
other tools (such as nodehun
, nspell
) or when making
such tools.
Install
In Node.js (14.14+, 16.0+), install with npm:
npm install dictionary-en
๐ Note: replaceen
with the language code you want.
โ ๏ธ Important: this project itself is MIT, but eachindex.dic
andindex.aff
file still has its original license!
Use
import dictionaryEn from 'dictionary-en'
dictionaryEn(function (error, en) {
if (error) throw error
console.log(en)
// To do: use `en` somehow
})
Yields:
{dic: <Buffer>, aff: <Buffer>}
List of dictionaries
๐ Note: preferred BCP-47 codes are used (according to Unicode CLDR). To illustrate, as American English and Brazilian Portuguese are the most common types of English and Portuguese respectively, they get the codesen
andpt
.
In total 92 dictionaries are provided.
Examples
nspell
Example: use with This example uses dictionary-en
in combination with nspell
.
Show install command for this example
npm install dictionary-en nspell
import dictionaryEn from 'dictionary-en'
import nspell from 'nspell'
dictionaryEn(function (error, en) {
if (error) throw error
const spell = nspell(en)
console.log(spell.correct('color'))
console.log(spell.correct('colour'))
})
Yields:
true
false
Example: load files from ESM
This example loads the index.dic
and index.aff
files located in
dictionary-hyw
(Western Armenian) from a Node.js JavaScript module (ESM).
It uses a ponyfill (import-meta-resolve
) for an
experimental Node API.
Show install command for this example
npm install dictionary-hyw import-meta-resolve
import fs from 'node:fs/promises'
import {resolve} from 'import-meta-resolve'
const base = await resolve('dictionary-hyw', import.meta.url)
const dic = await fs.readFile(new URL('index.dic', base))
const aff = await fs.readFile(new URL('index.aff', base))
console.log(dic, aff)
Example: load files from CommonJS
This example loads the index.dic
and index.aff
files located in
dictionary-tlh
(Klingon) from a Node.js CommonJS script (CJS).
Show install command for this example
npm install dictionary-tlh
const fs = require('node:fs')
const path = require('node:path')
const base = require.resolve('dictionary-tlh')
const dic = await fs.readFile(path.join(base, 'index.dic'))
const aff = await fs.readFile(path.join(base, 'index.aff'))
console.log(dic, aff)
Example: use with macOS
Follow these steps to use a dictionary on macOS:
- Navigate to the dictionary you want on GitHub, such as
dictionaries/$code
(replace$code
with the language code you want) - Download the
index.aff
andindex.dic
files (i.e., open them, right-click โRawโ, and โdownload linked filesโ) - Rename the download files to
$code.aff
and$code.dic
- Move
$code.aff
and$code.dic
into the folder~/Library/Spelling/
- Go to System Preferences > Keyboard > Text > Spelling and
select your added language (it should come with the
(Library)
suffix and is situated at the bottom)
Types
The dictionaries are typed with TypeScript.
Contribute
Yes please! See How to Contribute to Open Source.
Build
To build this project, on macOS, you at least need to install:
- wget:
brew install wget
(crawling) - hunspell:
brew install hunspell
(many dictionaries) - sed:
brew install gnu-sed
(crawling, many dictionaries) - coreutils:
brew install coreutils
(many dictionaries) - ispell:
brew install ispell
(German)
๐ Note: sed and the GNU replacements should be setup in PATH to overwrite macOS defaults.
Updating a dictionary
Dictionaries are not maintained here. Report problems upstream.
Adding a new dictionary
Dictionaries are not maintained here. Most languages have a small community or institute that maintains a dictionary, and they often do so on GitHub or similar. Please ask in the issues to request that such a dictionary is included here.
๐ Note: acceptable dictionaries must:
- have a significant affix file (not just a
.dic
file)- have an open source license
- have recent contributions
License
MIT ยฉ Titus Wormer
See license
files in each dictionary for the licensing of index.dic
and
index.aff
files.