mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 04:34:31 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@50259 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user