Make WordPress Core


Ignore:
Timestamp:
01/06/2019 05:05:24 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.

Merge of [44403] to the 5.0 branch.

Props swissspidy.
Fixes #45441.

Location:
branches/5.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0

  • branches/5.0/src/wp-includes/class.wp-scripts.php

    r43898 r44404  
    533533        }
    534534
    535         $output = '(function( translations ){' .
    536                       'translations.locale_data.messages[""].domain = "' . $domain . '";' .
    537                       'wp.i18n.setLocaleData( translations.locale_data.messages, "' . $domain . '" );' .
    538                   '})(' . $json_translations . ');';
     535        $output = <<<JS
     536( function( domain, translations ) {
     537    var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
     538    localeData[""].domain = domain;
     539    wp.i18n.setLocaleData( localeData, domain );
     540} )( "{$domain}", {$json_translations} );
     541JS;
    539542
    540543        if ( $echo ) {
     
    547550    /**
    548551     * Determines script dependencies.
    549     *
     552    *
    550553     * @since 2.1.0
    551554     *
Note: See TracChangeset for help on using the changeset viewer.