Make WordPress Core

Changeset 44239


Ignore:
Timestamp:
12/16/2018 10:23:34 PM (5 years ago)
Author:
SergeyBiryukov
Message:

I18N: Set translations for all WordPress packages scripts.

Calls wp_set_script_translations for all packages scripts that have translations. Also correctly sets the domain on the translations.

Props omarreiss, pento, ocean90.
Merges [43878] to trunk.
Fixes #45161.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/class.wp-scripts.php

    r44169 r44239  
    547547
    548548        $output = '(function( translations ){' .
    549                       'wp.i18n.setLocaleData( translations.locale_data, "' . $domain . '" );' .
     549                      'translations.locale_data.messages[""].domain = "' . $domain . '";' .
     550                      'wp.i18n.setLocaleData( translations.locale_data.messages, "' . $domain . '" );' .
    550551                  '})(' . $json_translations . ');';
    551552
  • trunk/src/wp-includes/script-loader.php

    r44238 r44239  
    320320        'i18n'                               => array( 'wp-polyfill' ),
    321321        'is-shallow-equal'                   => array( 'wp-polyfill' ),
    322         'keycodes'                           => array( 'lodash', 'wp-polyfill' ),
     322        'keycodes'                           => array( 'lodash', 'wp-polyfill', 'wp-i18n' ),
    323323        'list-reusable-blocks'               => array(
    324324            'lodash',
     
    362362    );
    363363
     364    $package_translations = array(
     365        'api-fetch'            => 'default',
     366        'blocks'               => 'default',
     367        'block-library'        => 'default',
     368        'components'           => 'default',
     369        'edit-post'            => 'default',
     370        'editor'               => 'default',
     371        'format-library'       => 'default',
     372        'keycodes'             => 'default',
     373        'list-reusable-blocks' => 'default',
     374        'nux'                  => 'default',
     375    );
     376
    364377    foreach ( $packages_dependencies as $package => $dependencies ) {
    365378        $handle = 'wp-' . $package;
     
    367380
    368381        $scripts->add( $handle, $path, $dependencies, false, 1 );
     382
     383        if ( isset( $package_translations[ $package ] ) ) {
     384            $scripts->set_translations( $handle, $package_translations[ $package ] );
     385        }
    369386    }
    370387}
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r44169 r44239  
    784784        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    785785        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    786                 'wp.i18n.setLocaleData( translations.locale_data, "default" );' .
    787             '})(' . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
     786                     'translations.locale_data.messages[""].domain = "default";' .
     787                     'wp.i18n.setLocaleData( translations.locale_data.messages, "default" );' .
     788                     '})(' . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
    788789        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
    789790
     
    801802        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    802803        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    803                      'wp.i18n.setLocaleData( translations.locale_data, "internationalized-plugin" );' .
     804                     'translations.locale_data.messages[""].domain = "internationalized-plugin";' .
     805                     'wp.i18n.setLocaleData( translations.locale_data.messages, "internationalized-plugin" );' .
    804806                     '})(' . file_get_contents( DIR_TESTDATA . '/languages/plugins/internationalized-plugin-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' ) . ");\n</script>\n";
    805807        $expected .= "<script type='text/javascript' src='/wp-content/plugins/my-plugin/js/script.js'></script>\n";
     
    818820        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    819821        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    820                      'wp.i18n.setLocaleData( translations.locale_data, "internationalized-theme" );' .
     822                     'translations.locale_data.messages[""].domain = "internationalized-theme";' .
     823                     'wp.i18n.setLocaleData( translations.locale_data.messages, "internationalized-theme" );' .
    821824                     '})(' . file_get_contents( DIR_TESTDATA . '/languages/themes/internationalized-theme-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' ) . ");\n</script>\n";
    822825        $expected .= "<script type='text/javascript' src='/wp-content/themes/my-theme/js/script.js'></script>\n";
     
    835838        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    836839        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    837                      'wp.i18n.setLocaleData( translations.locale_data, "admin" );' .
     840                     'translations.locale_data.messages[""].domain = "admin";' .
     841                     'wp.i18n.setLocaleData( translations.locale_data.messages, "admin" );' .
    838842                     '})(' . file_get_contents( DIR_TESTDATA . '/languages/admin-en_US-script-handle.json' ) . ");\n</script>\n";
    839843        $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js'></script>\n";
     
    887891        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    888892        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    889                      'wp.i18n.setLocaleData( translations.locale_data, "default" );' .
     893                     'translations.locale_data.messages[""].domain = "default";' .
     894                     'wp.i18n.setLocaleData( translations.locale_data.messages, "default" );' .
    890895                     '})(' . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
    891896        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
     
    906911        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    907912        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    908                      'wp.i18n.setLocaleData( translations.locale_data, "default" );' .
     913                     'translations.locale_data.messages[""].domain = "default";' .
     914                     'wp.i18n.setLocaleData( translations.locale_data.messages, "default" );' .
    909915                     '})(' . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
    910916        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
Note: See TracChangeset for help on using the changeset viewer.