From c8340a2cdafceb3c8dbc589ab8cc296a87888feb Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 10 Nov 2014 02:07:00 +0000 Subject: [PATCH] TinyMCE: enable direct calls to `_WP_Editors::wp_mce_translation()`. When using TinyMCE directly, this makes it easier to load the translation of the default strings. Fixes #30293. git-svn-id: https://develop.svn.wordpress.org/trunk@30296 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-editor.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 6e820d2ba3..e5eee08bd2 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -736,7 +736,15 @@ final class _WP_Editors { ) ); } - public static function wp_mce_translation() { + /** + * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n(). + * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object. + * + * @param string $mce_locale The locale used for the editor. + * @param bool $json_only optional Whether to include the Javascript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone(). + * @return The translation object, JSON encoded. + */ + public static function wp_mce_translation( $mce_locale = '', $json_only = false ) { $mce_translation = array( // Default TinyMCE strings @@ -962,8 +970,9 @@ final class _WP_Editors { * Url */ - $baseurl = self::$baseurl; - $mce_locale = self::$mce_locale; + if ( ! $mce_locale ) { + $mce_locale = self::$mce_locale; + } /** * Filter translated strings prepared for TinyMCE. @@ -992,6 +1001,12 @@ final class _WP_Editors { $mce_translation['_dir'] = 'rtl'; } + if ( $json_only ) { + return wp_json_encode( $mce_translation ); + } + + $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' ); + return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" . "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n"; }