This post is how to save a personal word list to TinyMCE’s spellcheck, or Add to Dictionary as I prefer to refer to it as.
As you might know, TinyMCE is capable of spellchecking, but what if we want to add a word to the dictionary so that the word never comes up again as a typo? After spending some time with Google, I never found a solution to my liking, so I had the unpleasurable task of adding the functionality myself. To my surprises, it was much easier that I expected.
Note: I am assuming that you already have TinyMCE and the spellchecker plugin installed along with PSell/ASpell. If not, here’s the wiki page.
Here’s how I did it.
First, the spellchecker plugin has to be configured for PSpell in config.php
//$config['general.engine'] = 'GoogleSpell'; $config['general.engine'] = 'PSpell';
Now, in the langs/en.js file I had to add what text would display in the suggested words to add the given word to the dictionary.
I added
add_dictionary:"Add to Dictionary",
to the file.
Next I renamed editor_plugin_src.js to editor_plugin.js and added
m.add({
title : 'spellchecker.add_dictionary',
onclick : function() {
t._sendRPC('addToDictionary', [t.selectedLang, e.target.innerHTML],
function(r) {
dom.remove(e.target, 1);
t._checkDone();
});
}
});
I placed this inside the _showMenu function, after
m.add({
title : 'spellchecker.ignore_words',
onclick : function() {
t._removeWords(dom.decode(e.target.innerHTML));
t._checkDone();
}
});
This adds our ‘Add to Dictionary’ option in our options that display when we click on a misspelled word and calls our addToDictionary function when selected.
Now we need to modify PSpell.php (inside the classes directory).
First we have to update the the _getPLink function.
Change
$plink = pspell_new( $lang, $this->_config['PSpell.spelling'], $this->_config['PSpell.jargon'], $this->_config['PSpell.encoding'], $this->_config['PSpell.mode'] );
to this
$pspell_config = pspell_config_create (
$lang,
$this->_config['PSpell.spelling'],
$this->_config['PSpell.jargon'],
$this->_config['PSpell.encoding']
);
pspell_config_personal ($pspell_config, realpath('.')."/custom_dictionary.pws");
$plink = pspell_new_config ($pspell_config);
This tells the spellchecker to create a personal dictionary and to use the custom_dictionary.pws. custom_dictionary.pws is the file that will hold all of the words we add to the dictionary. realpath(‘.’) will save this file inside our spellchecker plugin folder. You need to make sure that the web server has write permissions to this directory as well.
Now we’ll create our addToDictionary function, this is what will save our word to custom_dictionary.pws.
function &addToDictionary($lang, $word) {
$plink = $this->_getPLink($lang);
pspell_add_to_personal ($plink, $word);
pspell_save_wordlist ($plink);
return 'true';
}
I am simply returning ‘true’ as the function call expects a value returned.



Thank you very much for this, worked like a charm with JCE (Joomla Content Editor) which uses TinyMCE.
The only change i would make is the custom_dictionary location however this is easier enough to do.
One happy camper.
Thank you for sharing I wish I could go somwhere.