Fix wp.i18n.isRTL()

Fixes a bug causing wp.i18n.isRTL() to return false in RTL langauges by manually
loading the translated 'ltr' string for the i18n dependency. This ports over an
identical fix that was made in Gutenberg.

Fixes #52441.
Props @jonsurrell @youknowriad.

Built from https://develop.svn.wordpress.org/trunk@50259


git-svn-id: http://core.svn.wordpress.org/trunk@49904 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
noisysocks 2021-02-08 23:51:10 +00:00
parent 19dbb952f3
commit c6ec6cdc88
2 changed files with 13 additions and 1 deletions

View File

@ -267,6 +267,18 @@ function wp_default_packages_scripts( $scripts ) {
if ( in_array( 'wp-i18n', $dependencies, true ) ) {
$scripts->set_translations( $handle );
}
// Manually set the text direction localization after wp-i18n is
// printed. This ensures that wp.i18n.isRTL() returns true in RTL
// languages. We cannot use $scripts->set_translations( 'wp-i18n' ) to
// do this because WordPress prints a script's translations *before*
// printing the script, which means, in the case of wp-i18n, that
// wp.i18n.setLocaleData() is called before wp.i18n is defined.
if ( 'wp-i18n' === $handle ) {
$ltr = _x( 'ltr', 'text direction', 'default' );
$script = sprintf( "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ '%s' ] } );", $ltr );
$scripts->add_inline_script( $handle, $script, 'after' );
}
}
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.7-beta1-50258';
$wp_version = '5.7-beta1-50259';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.