Make WordPress Core


Ignore:
Timestamp:
01/06/2019 04:22:46 PM (6 years ago)
Author:
ocean90
Message:

I18N/Script Loader: Support text domains other than "messages".

The inline JavaScript added by WP_Scripts::print_translations() should check whether locale_data.$text_domain exists and fall back to locale_data.messages otherwise.

Props swissspidy.
See #45441.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-scripts.php

    r44395 r44403  
    547547        }
    548548
    549         $output = '(function( translations ){' .
    550                       'translations.locale_data.messages[""].domain = "' . $domain . '";' .
    551                       'wp.i18n.setLocaleData( translations.locale_data.messages, "' . $domain . '" );' .
    552                   '})(' . $json_translations . ');';
     549        $output = <<<JS
     550( function( domain, translations ) {
     551    var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
     552    localeData[""].domain = domain;
     553    wp.i18n.setLocaleData( localeData, domain );
     554} )( "{$domain}", {$json_translations} );
     555JS;
    553556
    554557        if ( $echo ) {
Note: See TracChangeset for help on using the changeset viewer.