Make WordPress Core


Ignore:
Timestamp:
04/03/2014 03:39:21 AM (11 years ago)
Author:
azaozz
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-editor.php

    r27901 r27922  
    271271            if ( empty( self::$first_init ) ) {
    272272                self::$baseurl = includes_url( 'js/tinymce' );
     273
    273274                $mce_locale = get_locale();
    274 
    275                 if ( empty( $mce_locale ) || 'en' == substr( $mce_locale, 0, 2 ) ) {
    276                     $mce_locale = 'en';
    277                 }
    278 
    279                 self::$mce_locale = $mce_locale;
     275                self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
    280276
    281277                /** This filter is documented in wp-admin/includes/media.php */
     
    393389                            $mce_external_plugins[ $name ] = $url;
    394390                            $plugurl = dirname( $url );
    395 
    396                             if ( in_array( $name, $loaded_langs ) ) {
    397                                 $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
     391                            $strings = $str1 = $str2 = '';
     392
     393                            // Try to load langs/[locale].js and langs/[locale]_dlg.js
     394                            if ( ! in_array( $name, $loaded_langs, true ) ) {
     395                                $path = str_replace( content_url(), '', $plugurl );
     396                                $path = WP_CONTENT_DIR . $path . '/langs/';
     397
     398                                if ( function_exists('realpath') )
     399                                    $path = trailingslashit( realpath($path) );
     400
     401                                if ( @is_file( $path . $mce_locale . '.js' ) )
     402                                    $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
     403
     404                                if ( @is_file( $path . $mce_locale . '_dlg.js' ) )
     405                                    $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
     406
     407                                if ( 'en' != $mce_locale && empty( $strings ) ) {
     408                                    if ( @is_file( $path . 'en.js' ) ) {
     409                                        $str1 = @file_get_contents( $path . 'en.js' );
     410                                        $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
     411                                    }
     412
     413                                    if ( @is_file( $path . 'en_dlg.js' ) ) {
     414                                        $str2 = @file_get_contents( $path . 'en_dlg.js' );
     415                                        $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
     416                                    }
     417                                }
     418
     419                                if ( ! empty( $strings ) )
     420                                    $ext_plugins .= "\n" . $strings . "\n";
    398421                            }
     422
     423                            $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
     424                            $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
    399425                        }
    400426                    }
Note: See TracChangeset for help on using the changeset viewer.