Title: mce_external_languages
Published: April 25, 2014
Last modified: May 20, 2026

---

# apply_filters( ‘mce_external_languages’, array $translations, string $editor_id )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#wp--skip-link--target)

Filters the translations loaded for external TinyMCE 3.x plugins.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#description)󠁿

The filter takes an associative array (‘plugin_name’ => ‘path’) where ‘path’ is 
the include path to the file.

The language file should follow the same format as wp_mce_translation(), and should
define a variable ($strings) that holds all translated strings.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#parameters)󠁿

 `$translations`array

Translations for external TinyMCE plugins.

`$editor_id`string

Unique editor identifier, e.g. `'content'`.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#source)󠁿

    ```php
    $mce_external_languages = apply_filters( 'mce_external_languages', array(), $editor_id );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-editor.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-editor.php#L489)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-editor.php#L489-L489)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#related)󠁿

| Used by | Description | 
| [_WP_Editors::editor_settings()](https://developer.wordpress.org/reference/classes/_wp_editors/editor_settings/)`wp-includes/class-wp-editor.php` |  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | The `$editor_id` parameter was added. | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/mce_external_languages/?output_format=md#comment-content-4845)
 2.    [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/mce_external_languages/#comment-4845)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fmce_external_languages%2F%23comment-4845)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fmce_external_languages%2F%23comment-4845)
 4.  Example Migrated from Codex:
 5.      ```php
         add_filter('mce_external_languages', 'my_custom_tinymce_plugin_add_locale');
     
         function my_custom_tinymce_plugin_add_locale($locales) {
             $locales ['My-Custom-Tinymce-Plugin'] = plugin_dir_path ( __FILE__ ) . 'my-custom-tinymce-plugin-langs.php';
             return $locales;
         }
         ```
     
 6.  Replace My-Custom-Tinymce-Plugin with your identifier of your plugin and make 
     sure the path to `my-custom-tinymce-plugin-langs.php` is correct.
 7.  **Translating strings with `mce_external_languages`**
 8.  Create a new file, called something like `my-custom-tinymce-plugin-langs.php` 
     and open it. Insert the following code.
 9.      ```php
         // This file is based on wp-includes/js/tinymce/langs/wp-langs.php
     
         if ( ! defined( 'ABSPATH' ) )
             exit;
     
         if ( ! class_exists( '_WP_Editors' ) )
             require( ABSPATH . WPINC . '/class-wp-editor.php' );
     
         function my_custom_tinymce_plugin_translation() {
             $strings = array(
                 'somestring' => __('My custom Tinymce plugin', 'textdomain'),
             );
             $locale = _WP_Editors::$mce_locale;
             $translated = 'tinyMCE.addI18n("' . $locale . '.my_custom_tinymce_plugin", ' . json_encode( $strings ) . ");\n";
     
              return $translated;
         }
     
         $strings = my_custom_tinymce_plugin_translation();
         ```
     
 10. **What the code does**
 11. The code first checks if the file is included by WordPress. If not, it exits. 
     Next, it checks if the class `_WP_Editors` exists. If not, the class is loaded(
     from wp-includes/class-wp-editor.php).
 12. We wrap the translation in a function (this to make sure there are no global variables)
     called `my_custom_tinymce_plugin_translation` (make 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 get the translation. Then
     we retrieve the locale for the editor and we build some JavaScript. We use the`
     tinyMCE.addI18n` JavaScript function to add the translated strings to the editor.
     Some information about the arguments:
 13. **`"' . $locale . '.my_custom_tinymce_plugin"`**
      This is the “textdomain” of 
     the translation. It should look rendered like “`en.my_custom_tinymce_plugin`” (
     the language, in this case en, is set to the value of the variable `$locale`).
     We use `my_custom_tinymce_plugin` as “textdomain”.
 14. **`json_encode( $strings ) `**
      This converts the translated strings to JavaScript.
 15. That bit of JavaScript code is returned by the function.
 16. You can see that on the last line of the file, our function `my_custom_tinymce_plugin_translation`
     is called and that the translated strings are saved in the global variable `$strings`(
     The variable has to be called `$strings`, or it won’t work).
 17. **Load the translations**
 18. Next, use the next code to make sure WordPress loads the translations
 19.     ```php
         unction my_custom_tinymce_plugin_add_locale($locales) {
             $locales ['My-Custom-Tinymce-Plugin'] = plugin_dir_path ( __FILE__ ) . 'my-custom-tinymce-plugin-langs.php';
             return $locales;
         }
         add_filter('mce_external_languages', 'my_custom_tinymce_plugin_add_locale');
         ```
     
 20. **Use the translations in your Javascript**
 21.     ```php
         // ed is the current tinymce editor.
         ed.getLang('my_custom_tinymce_plugin.somestring');
         ```
     
 22. This will return the translation of “My custom Tinymce plugin”.
 23.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fmce_external_languages%2F%3Freplytocom%3D4845%23feedback-editor-4845)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fmce_external_languages%2F)
before being able to contribute a note or feedback.