Make WordPress Core


Ignore:
Timestamp:
02/08/2021 11:49:33 PM (5 years ago)
Author:
noisysocks
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r50155 r50259  
    267267        if ( in_array( 'wp-i18n', $dependencies, true ) ) {
    268268            $scripts->set_translations( $handle );
     269        }
     270
     271        // Manually set the text direction localization after wp-i18n is
     272        // printed. This ensures that wp.i18n.isRTL() returns true in RTL
     273        // languages. We cannot use $scripts->set_translations( 'wp-i18n' ) to
     274        // do this because WordPress prints a script's translations *before*
     275        // printing the script, which means, in the case of wp-i18n, that
     276        // wp.i18n.setLocaleData() is called before wp.i18n is defined.
     277        if ( 'wp-i18n' === $handle ) {
     278            $ltr    = _x( 'ltr', 'text direction', 'default' );
     279            $script = sprintf( "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ '%s' ] } );", $ltr );
     280            $scripts->add_inline_script( $handle, $script, 'after' );
    269281        }
    270282    }
Note: See TracChangeset for help on using the changeset viewer.