The mce_external_languages WordPress PHP filter allows you to manage translations for external TinyMCE 3.x plugins.
Usage
add_filter('mce_external_languages', 'your_custom_function', 10, 2); function your_custom_function($translations, $editor_id) { // your custom code here return $translations; }
Parameters
- $translations (array): Translations for external TinyMCE plugins.
- $editor_id (string): Unique editor identifier, e.g., ‘content’.
More information
See WordPress Developer Resources: mce_external_languages
Examples
Add Translation File for Custom Plugin
This code adds a translation file for a custom TinyMCE plugin called ‘my_custom_plugin’.
add_filter('mce_external_languages', 'add_my_custom_plugin_translation', 10, 2); function add_my_custom_plugin_translation($translations, $editor_id) { $translations['my_custom_plugin'] = plugin_dir_path(__FILE__) . 'languages/my_custom_plugin_lang.php'; return $translations; }
Add Translation File for Multiple Plugins
This code adds translation files for multiple custom TinyMCE plugins.
add_filter('mce_external_languages', 'add_multiple_plugins_translation', 10, 2); function add_multiple_plugins_translation($translations, $editor_id) { $translations['plugin_one'] = plugin_dir_path(__FILE__) . 'languages/plugin_one_lang.php'; $translations['plugin_two'] = plugin_dir_path(__FILE__) . 'languages/plugin_two_lang.php'; return $translations; }
Remove Translation File for a Plugin
This code removes the translation file for a specific TinyMCE plugin.
add_filter('mce_external_languages', 'remove_plugin_translation', 10, 2); function remove_plugin_translation($translations, $editor_id) { unset($translations['plugin_to_remove']); return $translations; }
Modify Translation File for a Plugin
This code modifies the translation file for a specific TinyMCE plugin.
add_filter('mce_external_languages', 'modify_plugin_translation', 10, 2); function modify_plugin_translation($translations, $editor_id) { $translations['plugin_to_modify'] = plugin_dir_path(__FILE__) . 'languages/modified_plugin_lang.php'; return $translations; }
Conditionally Add Translation File
This code adds a translation file for a custom TinyMCE plugin only if a specific condition is met.
add_filter('mce_external_languages', 'conditionally_add_translation', 10, 2); function conditionally_add_translation($translations, $editor_id) { if (current_user_can('manage_options')) { $translations['conditional_plugin'] = plugin_dir_path(__FILE__) . 'languages/conditional_plugin_lang.php'; } return $translations; }