From 1c3cc504964015ba4679ce995283ca7b97a54086 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 3 Apr 2014 03:40:15 +0000 Subject: [PATCH] TinyMCE: - Bring back loading of /langs/[locale].js and /langs/[locale]_dlg.js from PHP. Prevents errors with missing translation files when custom plugins use requireLangPack() without second argument. - Back to using ISO 639-1 (two letter) locales as the locale is used as part of the translation file name. See #24067, fixes #27610 Built from https://develop.svn.wordpress.org/trunk@27922 git-svn-id: http://core.svn.wordpress.org/trunk@27752 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-editor.php | 42 ++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/wp-includes/class-wp-editor.php b/wp-includes/class-wp-editor.php index 3560e84a18..a3c26758d0 100644 --- a/wp-includes/class-wp-editor.php +++ b/wp-includes/class-wp-editor.php @@ -270,13 +270,9 @@ final class _WP_Editors { if ( empty( self::$first_init ) ) { self::$baseurl = includes_url( 'js/tinymce' ); + $mce_locale = get_locale(); - - if ( empty( $mce_locale ) || 'en' == substr( $mce_locale, 0, 2 ) ) { - $mce_locale = 'en'; - } - - self::$mce_locale = $mce_locale; + self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1 /** This filter is documented in wp-admin/includes/media.php */ $no_captions = (bool) apply_filters( 'disable_captions', '' ); @@ -392,10 +388,40 @@ final class _WP_Editors { $url = set_url_scheme( $url ); $mce_external_plugins[ $name ] = $url; $plugurl = dirname( $url ); + $strings = $str1 = $str2 = ''; - if ( in_array( $name, $loaded_langs ) ) { - $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n"; + // Try to load langs/[locale].js and langs/[locale]_dlg.js + if ( ! in_array( $name, $loaded_langs, true ) ) { + $path = str_replace( content_url(), '', $plugurl ); + $path = WP_CONTENT_DIR . $path . '/langs/'; + + if ( function_exists('realpath') ) + $path = trailingslashit( realpath($path) ); + + if ( @is_file( $path . $mce_locale . '.js' ) ) + $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n"; + + if ( @is_file( $path . $mce_locale . '_dlg.js' ) ) + $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n"; + + if ( 'en' != $mce_locale && empty( $strings ) ) { + if ( @is_file( $path . 'en.js' ) ) { + $str1 = @file_get_contents( $path . 'en.js' ); + $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n"; + } + + if ( @is_file( $path . 'en_dlg.js' ) ) { + $str2 = @file_get_contents( $path . 'en_dlg.js' ); + $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n"; + } + } + + if ( ! empty( $strings ) ) + $ext_plugins .= "\n" . $strings . "\n"; } + + $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n"; + $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n"; } } }