On this page
_WP_Editors::wp_mce_translation( string $mce_locale = '', bool $json_only = false ): string
Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n(), or as JS snippet that should run after tinymce.js is loaded.
Parameters
$mce_localestring Optional-
The locale used for the editor.
Default:
'' $json_onlybool Optional-
Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
Default:
false
Return
string Translation object, JSON encoded.
Source
File: wp-includes/class-wp-editor.php. View all references
public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
if ( ! $mce_locale ) {
$mce_locale = self::get_mce_locale();
}
$mce_translation = self::get_translation();
foreach ( $mce_translation as $name => $value ) {
if ( is_array( $value ) ) {
$mce_translation[ $name ] = $value[0];
}
}
/**
* Filters translated strings prepared for TinyMCE.
*
* @since 3.9.0
*
* @param array $mce_translation Key/value pairs of strings.
* @param string $mce_locale Locale.
*/
$mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
foreach ( $mce_translation as $key => $value ) {
// Remove strings that are not translated.
if ( $key === $value ) {
unset( $mce_translation[ $key ] );
continue;
}
if ( false !== strpos( $value, '&' ) ) {
$mce_translation[ $key ] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
}
}
// Set direction.
if ( is_rtl() ) {
$mce_translation['_dir'] = 'rtl';
}
if ( $json_only ) {
return wp_json_encode( $mce_translation );
}
$baseurl = self::get_baseurl();
return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
"tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
}
Hooks
- apply_filters( 'wp_mce_translation',
array $mce_translation ,string $mce_locale ) -
Filters translated strings prepared for TinyMCE.
Related
Uses
| Uses | Description |
|---|---|
| _WP_Editors::get_mce_locale() wp-includes/class-wp-editor.php | Returns the TinyMCE locale. |
| _WP_Editors::get_baseurl() wp-includes/class-wp-editor.php | Returns the TinyMCE base URL. |
| _WP_Editors::get_translation() wp-includes/class-wp-editor.php | |
| is_rtl() wp-includes/l10n.php | Determines whether the current locale is right-to-left (RTL). |
| wp_json_encode() wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| _WP_Editors::print_tinymce_scripts() wp-includes/class-wp-editor.php | Print (output) the main TinyMCE scripts. |
Changelog
| Version | Description |
|---|---|
| 3.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/_wp_editors/wp_mce_translation