如果您嘗試使用多個自訂字典,尤其是在您沒有系統 aspell 字典目錄的 sudo 權限時,這可能會有幫助⋯⋯
我使用「aspell create master」建立了三個自訂字典(或者說是單字列表),並找到了一種使用它們的方法⋯⋯
1) 建立 3 個單字列表,每行一個單字,分別為 wordlistA.txt、wordlistB.txt 和 wordlistC.txt。
2) 建立 3 個主字典檔... 使用 aspell --lang=en create master ./my_LANG-dictA.rws < wordlistA.txt - 針對 B 和 C 重複此步驟 (lang 語言需要已安裝,我想任何語言應該都可以)。
3) 建立 3 個多字典檔,my_LANGA.multi,內容:add my_LANG-dictA.rws) - 針對 B 和 C 重複此步驟。其中 my_LANGA 可以是任何名稱,大小寫需與 aspell 手冊中說明的一致。
4) 使用 pspell 搭配其中任何一個 (A、B 或 C) ...
<?php
$pspell_config = pspell_config_create('my_LANGC', '', ''. 'utf-8');
pspell_config_dict_dir($pspell_config, <my_LANGC.multi 的位置>);
if (($pspell = pspell_new_config($pspell_config)) == false) {
echo 'LANGC 的 pspell_new_config() 失敗!');
} else {
$word = 'PHPisgreat';
if (pspell_check($pspell, $word)) {
echo "$word: 拼寫正確";
} else {
$suggestions = pspell_suggest($pspell, $word);
echo "$word: 建議拼寫: $suggestions";
}
}
?>
pspell_config_create() 的語言參數是 .multi 檔案的基底名稱 (不含副檔名)。
請注意,我沒有 $HOME/.aspell.conf 檔案。
請注意,我的 .multi 和 .rws 檔案位於同一個目錄中,我認為這是必要的。
建立主字典檔後,就不再需要單字列表檔案。