Is there a way to get an array of dictionaries that pspell supports, preferably with their full human-readble names, using the PHP API?
For the time being I'm doing it this way:
$dicts = explode(PHP_EOL,rtrim(`aspell dicts`));
But that still doesn't give me the human-friendly version, (e.g., en_CA
might be "English - Canadian")
Here's what I came up with:
$dicts = explode(PHP_EOL,rtrim(`aspell dicts`));
$ltr = array();
foreach($dicts as $dict) {
if(preg_match('`^([a-z]+)$`',$dict,$m)) {
$lang = _iso639_1_to_lang_name($dict) ?: $dict;
} elseif(preg_match('`^([a-z]+)_([A-Z]+)$`',$dict,$m)) {
$lang = (_iso639_1_to_lang_name($m[1]) ?: $m[1]).' - '.(_country_code_to_adjectival($m[2])?:$m[2]);
} elseif(preg_match('`^([a-z]+)_([A-Z]+)-(.*)$`',$dict,$m)) {
$lang = (_iso639_1_to_lang_name($m[1]) ?: $m[1]).' - '.(_country_code_to_adjectival($m[2])?:$m[2]).' - '.ucwords(str_replace('_',' ',$m[3]));
} elseif(preg_match('`^([a-z]+)-(.*)$`',$dict,$m)) {
$lang = (_iso639_1_to_lang_name($m[1]) ?: $m[1]).' - '.ucwords(str_replace('_',' ',$m[2]));
} else {
$lang = $dict;
}
$ltr[$dict] = $lang;
}
Those functions just look up the full names from ISO codes based on data I scraped from Wikipedia.
Do you mean find out which dictionaries you have on your system? pspell is just a very thin wrapper over the GNU aspell library. It supports whatever the aspell library supports, but unfortunately it does not provide a way to list all the dictionaries. It would be nice if that functionality was added.