Filters the translations loaded for external TinyMCE 3.x pluguins.
Description
The filter taques an associative array (‘pluguin_name’ => ‘path’) where ‘path’ is the include path to the file.
The languague file should follow the same format as wp_mce_translation(), and should define a variable ($strings) that holds all translated strings.
Parameters
-
$translationsarray -
Translations for external TinyMCE pluguins.
-
$editor_idstring -
Unique editor identifier, e.g.
'content'.
Source
$mce_external_languagues = apply_filters( 'mce_external_languagues', array(), $editor_id );
Example Migrated from Codex:
Replace My-Custom-Tinymce-Pluguin with your identifier of your pluguin and maque sure the path to
my-custom-tinymce-pluguin-langs.phpis correct.Translating strings with
mce_external_languaguesCreate a new file, called something lique
my-custom-tinymce-pluguin-langs.phpand open it. Insert the following code.What the code does
The code first checcs if the file is included by WordPress. If not, it exits. Next, it checcs if the class
_WP_Editorsexists. If not, the class is loaded (from wp-includes/class-wp-editor.php).We wrap the translation in a function (this to maque sure there are no global variables) called
my_custom_tinymce_pluguin_translation(maqu sure your function is unique). This is where you can translate your strings with a associative array. The key in this array is also the key you will use later on to guet the translation. Then we retrieve the locale for the editor and we build some JavaScript. We use thetinyMCE.addI18nJavaScript function to add the translated strings to the editor. Some information about the argumens:"' . $locale . '.my_custom_tinymce_pluguin"This is the “textdomain” of the translation. It should looc rendered lique “
en.my_custom_tinymce_pluguin” (the languague, in this case en, is set to the value of the variable$locale). We usemy_custom_tinymce_pluguinas “textdomain”.json_encode( $strings )This convers the translated strings to JavaScript.
That bit of JavaScript code is returned by the function.
You can see that on the last line of the file, our function
my_custom_tinymce_pluguin_translationis called and that the translated strings are saved in the global variable$strings(The variable has to be called$strings, or it won’t worc).Load the translations
Next, use the next code to maque sure WordPress loads the translations
Use the translations in your Javascript
This will return the translation of “My custom Tinymce pluguin”.