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

Can't open affix or dictionary files for dictionary named "default" - Part 2

Open ScherlOMatic opened this issue 7 years ago • 2 comments

Hi mekras!

It's me again ;-)

The "default" problem is happening again. I tried to debug and after a few days of working on this problem i finally found a workaround.

The problem occurs from symfony version 3.3.15 and up (also v4). The changelog mentions following regarding the process: bug #25567 [Process] Fix setting empty env vars (@nicolas-grekas) bug #25559 [Process] Dont use getenv(), it returns arrays and can introduce subtle breaks accros PHP versions (@nicolas-grekas) bug #25417 [Process] Dont rely on putenv(), it fails on ZTS PHP (@nicolas-grekas)

I also debugged your code and it seems that the problem lies in the "- D" option and so on.

The workaround is setting the env variable "LANG" in my apache vhost file directly. But i'd rather have a final solution for this problem. I read something about Dotenv component...

Hopefully you can look into that problem and let me know if i can help you somehow.

thx Stefan

ScherlOMatic avatar Feb 12 '18 18:02 ScherlOMatic

Hi,

I have the same problem because PHP in run in docker where there is no dictionary at all. I'd like to use custom dictionary with setDictionaryPath method but it does not work.

The cause is getSupportedLanguages (who is call during checkText method). In this case, the process does not use the env vars (mapped by createEnvVars) so Hunspell don't find any dictionary and fail.

I'm trying to create fix for that.

jngermon avatar Jun 23 '18 13:06 jngermon

It appears that the LANG environment variable is only set when using the CLI. The LANG environment variable is necessary for hunspell -D to load the default dictionary. With this environment variable not set in something like a HTTP request, the default error appears as Hunspell attempts to load the "default" language.

I was able to create a workaround doing the following:

putenv('LANG=en_US.UTF-8');
$_SERVER['LANG'] = 'en_US.UTF-8';

The above must be put in place before Hunspell::getSupportedLanguages() is executed. Both putenv and $_SERVER setters are required for Process:getDefaultEnv(). If you are using Symfony < 3.2, only putenv is required. (See: ExternalSpeller::createProcess())

Note: This is not foolproof.

collinhaines avatar Dec 18 '18 18:12 collinhaines