WordPress.org

Make WordPress Core

Changeset 43878


Ignore:
Timestamp:
11/08/2018 11:33:46 AM (12 months ago)
Author:
herregroen
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.
Fixes #45161.

Location:
branches/5.0
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-admin/edit-form-blocks.php

    r43861 r43878  
    115115    );
    116116}
    117 
    118 // Prepare Jed locale data.
    119 $locale_data = wp_get_jed_locale_data( 'default' );
    120 wp_add_inline_script(
    121     'wp-i18n',
    122     'wp.i18n.setLocaleData( ' . wp_json_encode( $locale_data ) . ' );'
    123 );
    124117
    125118// Preload server-registered block schemas.
  • branches/5.0/src/wp-includes/class.wp-scripts.php

    r43859 r43878  
    533533
    534534        $output = '(function( translations ){' .
    535                       'wp.i18n.setLocaleData( translations.locale_data, "' . $domain . '" );' .
     535                      'translations.locale_data.messages[""].domain = "' . $domain . '";' .
     536                      'wp.i18n.setLocaleData( translations.locale_data.messages, "' . $domain . '" );' .
    536537                  '})(' . $json_translations . ');';
    537538
  • branches/5.0/src/wp-includes/script-loader.php

    r43877 r43878  
    321321        'i18n' => array( 'wp-polyfill' ),
    322322        'is-shallow-equal' => array( 'wp-polyfill' ),
    323         'keycodes' => array( 'lodash', 'wp-polyfill' ),
     323        'keycodes' => array( 'lodash', 'wp-polyfill', 'wp-i18n' ),
    324324        'list-reusable-blocks' => array(
    325325            'lodash',
     
    364364    );
    365365
     366    $package_translations = array(
     367        'api-fetch' => 'default',
     368        'blocks' => 'default',
     369        'block-library' => 'default',
     370        'components' => 'default',
     371        'edit-post' => 'default',
     372        'editor' => 'default',
     373        'format-library' => 'default',
     374        'keycodes' => 'default',
     375        'list-reusable-blocks' => 'default',
     376        'nux' => 'default',
     377    );
     378
    366379    foreach ( $packages_dependencies as $package => $dependencies ) {
    367380        $handle  = 'wp-' . $package;
     
    369382
    370383        $scripts->add( $handle, $path, $dependencies, false, 1 );
     384
     385        if ( isset( $package_translations[ $package ] ) ) {
     386            $scripts->set_translations( $handle, $package_translations[ $package ] );
     387        }
    371388    }
    372389}
  • branches/5.0/tests/phpunit/tests/dependencies/scripts.php

    r43859 r43878  
    778778        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    779779        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    780                 "wp.i18n.setLocaleData( translations.locale_data, \"default\" );" .
    781             "})(" . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
     780                     "translations.locale_data.messages[\"\"].domain = \"default\";" .
     781                     "wp.i18n.setLocaleData( translations.locale_data.messages, \"default\" );" .
     782                     "})(" . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
    782783        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
    783784
     
    795796        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    796797        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    797                      "wp.i18n.setLocaleData( translations.locale_data, \"internationalized-plugin\" );" .
     798                     "translations.locale_data.messages[\"\"].domain = \"internationalized-plugin\";" .
     799                     "wp.i18n.setLocaleData( translations.locale_data.messages, \"internationalized-plugin\" );" .
    798800                     "})(" . file_get_contents( DIR_TESTDATA . '/languages/plugins/internationalized-plugin-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' ) . ");\n</script>\n";
    799801        $expected .= "<script type='text/javascript' src='/wp-content/plugins/my-plugin/js/script.js'></script>\n";
     
    812814        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    813815        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    814                      "wp.i18n.setLocaleData( translations.locale_data, \"internationalized-theme\" );" .
     816                     "translations.locale_data.messages[\"\"].domain = \"internationalized-theme\";" .
     817                     "wp.i18n.setLocaleData( translations.locale_data.messages, \"internationalized-theme\" );" .
    815818                     "})(" . file_get_contents( DIR_TESTDATA . '/languages/themes/internationalized-theme-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' ) . ");\n</script>\n";
    816819        $expected .= "<script type='text/javascript' src='/wp-content/themes/my-theme/js/script.js'></script>\n";
     
    829832        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    830833        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    831                      "wp.i18n.setLocaleData( translations.locale_data, \"admin\" );" .
     834                     "translations.locale_data.messages[\"\"].domain = \"admin\";" .
     835                     "wp.i18n.setLocaleData( translations.locale_data.messages, \"admin\" );" .
    832836                     "})(" . file_get_contents( DIR_TESTDATA . '/languages/admin-en_US-script-handle.json' ) . ");\n</script>\n";
    833837        $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js'></script>\n";
     
    877881        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    878882        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    879                      "wp.i18n.setLocaleData( translations.locale_data, \"default\" );" .
     883                     "translations.locale_data.messages[\"\"].domain = \"default\";" .
     884                     "wp.i18n.setLocaleData( translations.locale_data.messages, \"default\" );" .
    880885                     "})(" . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
    881886        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
     
    896901        $expected  = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
    897902        $expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
    898                      "wp.i18n.setLocaleData( translations.locale_data, \"default\" );" .
     903                     "translations.locale_data.messages[\"\"].domain = \"default\";" .
     904                     "wp.i18n.setLocaleData( translations.locale_data.messages, \"default\" );" .
    899905                     "})(" . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
    900906        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
Note: See TracChangeset for help on using the changeset viewer.