Make WordPress Core


Ignore:
Timestamp:
12/14/2018 05:51:31 AM (6 years ago)
Author:
pento
Message:

I18N: Add JavaScript translation support.

Adds the wp_set_script_translations() function which registers translations for a JavaScript file. This function takes a handle, domain and optionally a path and ensures JavaScript translation files are loaded if they exist.

Merges [43825,43828,43859,43898] from the 5.0 branch to trunk.

Props herregroen, atimmer, omarreiss, nerrad, swissspidy, ocean90, georgestephanis.
Fixes #45103, #45256.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/functions.wp-scripts.php

    r43661 r44169  
    199199
    200200    return $wp_scripts->localize( $handle, $object_name, $l10n );
     201}
     202
     203/**
     204 * Sets translated strings for a script.
     205 *
     206 * Works only if the script has already been added.
     207 *
     208 * @see WP_Scripts::set_translations()
     209 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
     210 *
     211 * @since 5.0.0
     212 *
     213 * @param string $handle Script handle the textdomain will be attached to.
     214 * @param string $domain The textdomain.
     215 * @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 */
     219function wp_set_script_translations( $handle, $domain, $path = null ) {
     220    global $wp_scripts;
     221    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
     222        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     223        return false;
     224    }
     225
     226    return $wp_scripts->set_translations( $handle, $domain, $path );
    201227}
    202228
Note: See TracChangeset for help on using the changeset viewer.