Make WordPress Core

Changeset 43898 for branches/5.0


Ignore:
Timestamp:
11/15/2018 02:36:39 PM (8 years ago)
Author:
herregroen
Message:

I18N: Fix warnings in JavaScript translations.

Fixes an undefined index PHP warning in the load_script_textdomain function and a non-interrupting JS error when registering a domain which has no translations.

Props omarreiss, ocean90, georgestephanis.
Fixes #45256.

Location:
branches/5.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/class.wp-scripts.php

    r43878 r43898  
    529529
    530530                if ( ! $json_translations ) {
    531                         return false;
     531                        // Register empty locale data object to ensure the domain still exists.
     532                        $json_translations = '{ "locale_data": { "messages": { "": {} } } }';
    532533                }
    533534
  • branches/5.0/src/wp-includes/l10n.php

    r43859 r43898  
    924924                $relative = array_slice( $relative, 2 );
    925925                $relative = implode( '/', $relative );
    926         } else if (
    927                 ! isset( $site_url['path'] ) &&
    928                 ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] )
    929         ) {
    930                 $relative = trim( $src_url['path'], '/' );
    931         } else if (
    932                 ( strpos( $src_url['path'], $site_url['path'] ) === 0 ) &&
    933                 ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] )
    934         ) {
    935                 // Make the src relative to the WP root.
    936                 $relative = substr( $src, strlen( $site_url['path'] ) );
    937                 $relative = trim( $relative, '/' );
     926        } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) {
     927                if ( ! isset( $site_url['path'] ) ) {
     928                        $relative = trim( $src_url['path'], '/' );
     929                } elseif ( ( strpos( $src_url['path'], $site_url['path'] ) === 0 ) ) {
     930                        // Make the src relative to the WP root.
     931                        $relative = substr( $src, strlen( $site_url['path'] ) );
     932                        $relative = trim( $relative, '/' );
     933                }
    938934        }
    939935
  • branches/5.0/tests/phpunit/tests/dependencies/scripts.php

    r43878 r43898  
    864864
    865865                $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    866                 $expected .= "\n<script type='text/javascript' src='/wp-admin/js/script.js'></script>\n";
     866                $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
     867                             "translations.locale_data.messages[\"\"].domain = \"admin\";" .
     868                             "wp.i18n.setLocaleData( translations.locale_data.messages, \"admin\" );" .
     869                             "})({ \"locale_data\": { \"messages\": { \"\": {} } } });\n</script>\n";
     870                $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js'></script>\n";
    867871
    868872                $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
Note: See TracChangeset for help on using the changeset viewer.