WordPress.org

Make WordPress Core

Changeset 44395


Ignore:
Timestamp:
01/04/2019 09:11:01 PM (20 months ago)
Author:
ocean90
Message:

I18N: Make domain argument optional in wp_set_script_translations() / WP_Scripts::set_translations().

Props swissspidy.
Fixes #45489.

Location:
trunk/src/wp-includes
Files:
4 edited

Legend:

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

    r44239 r44395  
    500500     *
    501501     * @since 5.0.0
     502     * @since 5.1.0 The `$domain` parameter was made optional.
    502503     *
    503504     * @param string $handle Name of the script to register a translation domain to.
    504      * @param string $domain The textdomain.
     505     * @param string $domain Optional. Text domain. Default 'default'.
    505506     * @param string $path   Optional. The full file path to the directory containing translation files.
    506      *
    507      * @return bool True if the textdomain was registered, false if not.
    508      */
    509     public function set_translations( $handle, $domain, $path = null ) {
     507     * @return bool True if the text domain was registered, false if not.
     508     */
     509    public function set_translations( $handle, $domain = 'default', $path = null ) {
    510510        if ( ! isset( $this->registered[ $handle ] ) ) {
    511511            return false;
     
    518518            $obj->deps[] = 'wp-i18n';
    519519        }
     520
    520521        return $obj->set_translations( $domain, $path );
    521522    }
  • trunk/src/wp-includes/functions.wp-scripts.php

    r44350 r44395  
    210210 *
    211211 * @since 5.0.0
     212 * @since 5.1.0 The `$domain` parameter was made optional.
    212213 *
    213214 * @param string $handle Script handle the textdomain will be attached to.
    214  * @param string $domain The textdomain.
     215 * @param string $domain Optional. Text domain. Default 'default'.
    215216 * @param string $path   Optional. The full file path to the directory containing translation files.
    216  *
    217  * @return bool True if the textdomain was successfully localized, false otherwise.
    218  */
    219 function wp_set_script_translations( $handle, $domain, $path = null ) {
     217 * @return bool True if the text domain was successfully localized, false otherwise.
     218 */
     219function wp_set_script_translations( $handle, $domain = 'default', $path = null ) {
    220220    global $wp_scripts;
    221221    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
  • trunk/src/wp-includes/l10n.php

    r44318 r44395  
    899899 * @since 5.0.0
    900900 * @since 5.0.2 Uses load_script_translations() to load translation data.
     901 * @since 5.1.0 The `$domain` parameter was made optional.
    901902 *
    902903 * @see WP_Scripts::set_translations()
    903904 *
    904905 * @param string $handle Name of the script to register a translation domain to.
    905  * @param string $domain The text domain.
     906 * @param string $domain Optional. Text domain. Default 'default'.
    906907 * @param string $path   Optional. The full file path to the directory containing translation files.
    907908 *
     
    909910 *                      in JSON encoding otherwise.
    910911 */
    911 function load_script_textdomain( $handle, $domain, $path = null ) {
     912function load_script_textdomain( $handle, $domain = 'default', $path = null ) {
    912913    $wp_scripts = wp_scripts();
    913914
  • trunk/src/wp-includes/script-loader.php

    r44391 r44395  
    467467
    468468    $package_translations = array(
    469         'api-fetch'            => 'default',
    470         'blocks'               => 'default',
    471         'block-library'        => 'default',
    472         'components'           => 'default',
    473         'edit-post'            => 'default',
    474         'editor'               => 'default',
    475         'format-library'       => 'default',
    476         'keycodes'             => 'default',
    477         'list-reusable-blocks' => 'default',
    478         'nux'                  => 'default',
     469        'api-fetch',
     470        'blocks',
     471        'block-library',
     472        'components',
     473        'edit-post',
     474        'editor',
     475        'format-library',
     476        'keycodes',
     477        'list-reusable-blocks',
     478        'nux',
    479479    );
    480480
     
    486486        $scripts->add( $handle, $path, $dependencies, $version, 1 );
    487487
    488         if ( isset( $package_translations[ $package ] ) ) {
    489             $scripts->set_translations( $handle, $package_translations[ $package ] );
     488        if ( in_array( $package, $package_translations, true ) ) {
     489            $scripts->set_translations( $handle );
    490490        }
    491491    }
Note: See TracChangeset for help on using the changeset viewer.