php-spellchecker icon indicating copy to clipboard operation
php-spellchecker copied to clipboard

Custom dictionary and additional CLI arguments.

Open earthlingdavey opened this issue 3 months ago • 0 comments

Hi Philippe,

Thanks for this awesome library. It's saved my a fair amount of time :)

I just wanted to share my current workaround for using a custom dictionary with hunspell.

Currently I don't think there is a better way of doing this. Is that right?

// Start a workaround to set the dictionary file.
// This is needed because the Hunspell class does not allow setting the dictionary file directly.

// 1. Get the binary path.
$binary_path = $this->hunspell->getBinaryPath();

// 2. Add the dictionary file as an argument.
$binary_path = $binary_path->addArgs(['-p', $dictionary_file]);

// 3. Reconstruct the Hunspell instance with the new binary path.
// Note that `__construct` is a public method, so we can call it directly.
$this->hunspell->__construct($binary_path);

earthlingdavey avatar Sep 08 '25 10:09 earthlingdavey