I18N: Make domain argument optional in `wp_set_script_translations()` / `WP_Scripts::set_translations()`.
Props swissspidy. Fixes #45489. Built from https://develop.svn.wordpress.org/trunk@44395 git-svn-id: http://core.svn.wordpress.org/trunk@44225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8035cf38b7
commit
f34e1dbad1
|
@ -499,14 +499,14 @@ class WP_Scripts extends WP_Dependencies {
|
||||||
* Sets a translation textdomain.
|
* Sets a translation textdomain.
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @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 $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.
|
* @param string $path Optional. The full file path to the directory containing translation files.
|
||||||
*
|
* @return bool True if the text domain was registered, false if not.
|
||||||
* @return bool True if the textdomain 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 ] ) ) {
|
if ( ! isset( $this->registered[ $handle ] ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -517,6 +517,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||||
if ( ! in_array( 'wp-i18n', $obj->deps, true ) ) {
|
if ( ! in_array( 'wp-i18n', $obj->deps, true ) ) {
|
||||||
$obj->deps[] = 'wp-i18n';
|
$obj->deps[] = 'wp-i18n';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $obj->set_translations( $domain, $path );
|
return $obj->set_translations( $domain, $path );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,14 +209,14 @@ function wp_localize_script( $handle, $object_name, $l10n ) {
|
||||||
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
|
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @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 $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.
|
* @param string $path Optional. The full file path to the directory containing translation files.
|
||||||
*
|
* @return bool True if the text domain was successfully localized, false otherwise.
|
||||||
* @return bool True if the textdomain 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;
|
global $wp_scripts;
|
||||||
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
|
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
|
||||||
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
|
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
|
||||||
|
|
|
@ -898,17 +898,18 @@ function load_child_theme_textdomain( $domain, $path = false ) {
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
* @since 5.0.2 Uses load_script_translations() to load translation data.
|
* @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()
|
* @see WP_Scripts::set_translations()
|
||||||
*
|
*
|
||||||
* @param string $handle Name of the script to register a translation domain to.
|
* @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.
|
* @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
|
* @return false|string False if the script textdomain could not be loaded, the translated strings
|
||||||
* in JSON encoding otherwise.
|
* 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();
|
$wp_scripts = wp_scripts();
|
||||||
|
|
||||||
if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
|
if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
|
||||||
|
|
|
@ -466,16 +466,16 @@ function wp_default_packages_scripts( &$scripts ) {
|
||||||
);
|
);
|
||||||
|
|
||||||
$package_translations = array(
|
$package_translations = array(
|
||||||
'api-fetch' => 'default',
|
'api-fetch',
|
||||||
'blocks' => 'default',
|
'blocks',
|
||||||
'block-library' => 'default',
|
'block-library',
|
||||||
'components' => 'default',
|
'components',
|
||||||
'edit-post' => 'default',
|
'edit-post',
|
||||||
'editor' => 'default',
|
'editor',
|
||||||
'format-library' => 'default',
|
'format-library',
|
||||||
'keycodes' => 'default',
|
'keycodes',
|
||||||
'list-reusable-blocks' => 'default',
|
'list-reusable-blocks',
|
||||||
'nux' => 'default',
|
'nux',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $packages_dependencies as $package => $dependencies ) {
|
foreach ( $packages_dependencies as $package => $dependencies ) {
|
||||||
|
@ -485,8 +485,8 @@ function wp_default_packages_scripts( &$scripts ) {
|
||||||
|
|
||||||
$scripts->add( $handle, $path, $dependencies, $version, 1 );
|
$scripts->add( $handle, $path, $dependencies, $version, 1 );
|
||||||
|
|
||||||
if ( isset( $package_translations[ $package ] ) ) {
|
if ( in_array( $package, $package_translations, true ) ) {
|
||||||
$scripts->set_translations( $handle, $package_translations[ $package ] );
|
$scripts->set_translations( $handle );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue