Throws runtime exception when loading languages
public function getSupportedLanguages()
{
if (null === $this->supportedLanguages) {
$process = $this->createProcess('-D');
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException(sprintf('hunspell: %s', $process->getErrorOutput()));
}
Is throwing an exception when the command is seemingly producing the correct output:
Command output:
.::/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/home/vagrant/.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/hunspell/en_US
LOADED DICTIONARY:
/usr/share/hunspell/en_US.aff
/usr/share/hunspell/en_US.dic
Hunspell 1.3.2
>
Error output:
-- Error message --
hunspell: SEARCH PATH:
.::/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/var/empty/.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/hunspell/en_US
Can't open affix or dictionary files for dictionary named "default"
Hunspell can't find some dictionary files:
Can't open affix or dictionary files for dictionary named "default"
Do you use custom dictionaries? Can you show your code?
Sadly it's proprietary :( I'm pointing it at the standard US dict (hunspell-en-us) that ships with Ubuntu LTS 14.04 (which is named as shown above).
Can you show just a part of code where you creating and configuring Hunspell instance?
public function spellcheck() {
$tokens = $this->bodyParameters();
$corrections = [];
$dict = [ 'en_US' ];
$speller = new Hunspell( '/usr/bin/hunspell' );
//$speller->setLanguages( $dict );
$source = new StringSource( implode( ',', $tokens[ 'words' ] ) );
foreach ( $speller->checkText( $source, $dict ) as $suggestion ) {
$word = $suggestion->word;
$corrections[ $word ] = $suggestion->suggestions;
}
return $this->respond( $corrections );
}
That function I've commented out is how I've gotten around it for now (I forked the repo and added it). I also experimented w/changing the command passed (the block where the default languages are parsed from the output of hunspell -D) to the CLI, specifying the dict allowed it to work.
Hmm… Still can't reproduce. I've installed Hunspell 1.3.3:
mekras@mekras ~/t/h/usr> env LD_LIBRARY_PATH=lib64 bin/hunspell -v
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.3)
And use this test code:
<?php
use Mekras\Speller\Hunspell\Hunspell;
use Mekras\Speller\Source\StringSource;
require __DIR__ . '/vendor/autoload.php';
$dict = [ 'en_US' ];
$speller = new Hunspell( 'LD_LIBRARY_PATH=/home/mekras/tmp/hunspell/usr/lib64 /home/mekras/tmp/hunspell/usr/bin/hunspell' );
$source = new StringSource( 'tigr,cta,brid' );
foreach ( $speller->checkText( $source, $dict ) as $suggestion ) {
print_r($suggestion->suggestions);
}
Works fine. I have no ideas… :-(
On my server the dictionaries are stored under /usr/share/myspell, and I know this is not the best way to solve it, but for example, if your default language is en_US, then inside that folder, make a copy of the en_US.aff file and the en_US.dic file and then rename the copies to default.aff and default.dic respectively. This solved the issue for me. Hope this helps.
just set LANG
if (getenv('LANG') == false) {
putenv('LANG=en_US.UTF-8');
}