diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php index e843233cbc..26fbd6da9b 100644 --- a/wp-includes/class.wp-scripts.php +++ b/wp-includes/class.wp-scripts.php @@ -499,14 +499,14 @@ class WP_Scripts extends WP_Dependencies { * Sets a translation textdomain. * * @since 5.0.0 + * @since 5.1.0 The `$domain` parameter was made optional. * * @param string $handle Name of the script to register a translation domain to. - * @param string $domain The textdomain. + * @param string $domain Optional. Text domain. Default 'default'. * @param string $path Optional. The full file path to the directory containing translation files. - * - * @return bool True if the textdomain was registered, false if not. + * @return bool True if the text domain was registered, false if not. */ - public function set_translations( $handle, $domain, $path = null ) { + public function set_translations( $handle, $domain = 'default', $path = null ) { if ( ! isset( $this->registered[ $handle ] ) ) { return false; } @@ -517,6 +517,7 @@ class WP_Scripts extends WP_Dependencies { if ( ! in_array( 'wp-i18n', $obj->deps, true ) ) { $obj->deps[] = 'wp-i18n'; } + return $obj->set_translations( $domain, $path ); } diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php index 5aa26cca5e..2e99067f90 100644 --- a/wp-includes/functions.wp-scripts.php +++ b/wp-includes/functions.wp-scripts.php @@ -209,14 +209,14 @@ function wp_localize_script( $handle, $object_name, $l10n ) { * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. * * @since 5.0.0 + * @since 5.1.0 The `$domain` parameter was made optional. * * @param string $handle Script handle the textdomain will be attached to. - * @param string $domain The textdomain. + * @param string $domain Optional. Text domain. Default 'default'. * @param string $path Optional. The full file path to the directory containing translation files. - * - * @return bool True if the textdomain was successfully localized, false otherwise. + * @return bool True if the text domain was successfully localized, false otherwise. */ -function wp_set_script_translations( $handle, $domain, $path = null ) { +function wp_set_script_translations( $handle, $domain = 'default', $path = null ) { global $wp_scripts; if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 7dd86607ec..fb88ba5e07 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -898,17 +898,18 @@ function load_child_theme_textdomain( $domain, $path = false ) { * * @since 5.0.0 * @since 5.0.2 Uses load_script_translations() to load translation data. + * @since 5.1.0 The `$domain` parameter was made optional. * * @see WP_Scripts::set_translations() * * @param string $handle Name of the script to register a translation domain to. - * @param string $domain The text domain. + * @param string $domain Optional. Text domain. Default 'default'. * @param string $path Optional. The full file path to the directory containing translation files. * * @return false|string False if the script textdomain could not be loaded, the translated strings * in JSON encoding otherwise. */ -function load_script_textdomain( $handle, $domain, $path = null ) { +function load_script_textdomain( $handle, $domain = 'default', $path = null ) { $wp_scripts = wp_scripts(); if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 7f745acffd..bc21f9cbac 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -466,16 +466,16 @@ function wp_default_packages_scripts( &$scripts ) { ); $package_translations = array( - 'api-fetch' => 'default', - 'blocks' => 'default', - 'block-library' => 'default', - 'components' => 'default', - 'edit-post' => 'default', - 'editor' => 'default', - 'format-library' => 'default', - 'keycodes' => 'default', - 'list-reusable-blocks' => 'default', - 'nux' => 'default', + 'api-fetch', + 'blocks', + 'block-library', + 'components', + 'edit-post', + 'editor', + 'format-library', + 'keycodes', + 'list-reusable-blocks', + 'nux', ); foreach ( $packages_dependencies as $package => $dependencies ) { @@ -485,8 +485,8 @@ function wp_default_packages_scripts( &$scripts ) { $scripts->add( $handle, $path, $dependencies, $version, 1 ); - if ( isset( $package_translations[ $package ] ) ) { - $scripts->set_translations( $handle, $package_translations[ $package ] ); + if ( in_array( $package, $package_translations, true ) ) { + $scripts->set_translations( $handle ); } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index df9cff38fb..f0fd2bed0a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-44394'; +$wp_version = '5.1-alpha-44395'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.