Make WordPress Core

Ticket #45425: 45425.2.diff

File 45425.2.diff, 4.8 KB (added by ocean90, 6 years ago)
  • src/wp-includes/l10n.php

     
    870870}
    871871
    872872/**
    873  * Load the script translated strings.
     873 * Loads the script translated strings.
    874874 *
    875875 * @see WP_Scripts::set_translations()
    876  * @link https://core.trac.wordpress.org/ticket/45103
     876 *
    877877 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
    878878 *
    879879 * @since 5.0.0
     880 * @since 5.0.2 Uses load_script_translations() to load translations.
    880881 *
    881882 * @param string $handle Name of the script to register a translation domain to.
    882883 * @param string $domain The textdomain.
     
    899900        $file_base       = $domain === 'default' ? $locale : $domain . '-' . $locale;
    900901        $handle_filename = $file_base . '-' . $handle . '.json';
    901902        if ( $path && file_exists( $path . '/' . $handle_filename ) ) {
    902                 return file_get_contents( $path . '/' . $handle_filename );
     903                return load_script_translations( $path . '/' . $handle_filename, $handle, $domain );
    903904        }
    904905
    905906        $obj = $wp_scripts->registered[ $handle ];
     
    953954
    954955        // If the source is not from WP.
    955956        if ( false === $relative ) {
    956                 return false;
     957                return load_script_translations( false, $handle, $domain );
    957958        }
    958959
    959960        // Translations are always based on the unminified filename.
     
    963964
    964965        $md5_filename = $file_base . '-' . md5( $relative ) . '.json';
    965966        if ( $path && file_exists( $path . '/' . $md5_filename ) ) {
    966                 return file_get_contents( $path . '/' . $md5_filename );
     967                return load_script_translations( $path . '/' . $md5_filename, $handle, $domain );
    967968        }
    968969        if ( file_exists( $languages_path . '/' . $md5_filename ) ) {
    969                 return file_get_contents( $languages_path . '/' . $md5_filename );
     970                return load_script_translations( $languages_path . '/' . $md5_filename, $handle, $domain );
    970971        }
    971972
    972         return false;
     973        return load_script_translations( false, $handle, $domain );
    973974}
    974975
    975976/**
     977 * Loads the translated strings for the given script handle and text domain.
     978 *
     979 * @since 5.0.2
     980 *
     981 * @param string|false $file   Path to the translation file to load. False if there isn't one.
     982 * @param string       $handle Name of the script to register a translation domain to.
     983 * @param string       $domain The text domain.
     984 * @return string|false The JSON-encoded translated strings for the given script handle and text domain. False if there are none.
     985 */
     986function load_script_translations( $file, $handle, $domain ) {
     987        /**
     988         * Pre-filters script translations for the given file, script handle and text domain.
     989         *
     990         * Returning a non-null value allows to override the default logic, effectively short-circuiting the function.
     991         *
     992         * @since 5.0.2
     993         *
     994         * @param string|false $translations JSON-encoded translation data. Default null.
     995         * @param string|false $file         Path to the translation file to load. False if there isn't one.
     996         * @param string       $handle       Name of the script to register a translation domain to.
     997         * @param string       $domain       The text domain.
     998         */
     999        $translations = apply_filters( 'pre_load_script_translations', null, $file, $handle, $domain );
     1000
     1001        if ( null !== $translations ) {
     1002                return $translations;
     1003        }
     1004
     1005        /**
     1006         * Filters the file path for loading script translations for the given script handle and text domain.
     1007         *
     1008         * @since 5.0.2
     1009         *
     1010         * @param string|false $file   Path to the translation file to load. False if there isn't one.
     1011         * @param string       $handle Name of the script to register a translation domain to.
     1012         * @param string       $domain The text domain.
     1013         */
     1014        $file = apply_filters( 'load_script_translation_file', $file, $handle, $domain );
     1015
     1016        if ( ! $file || ! is_readable( $file ) ) {
     1017                return false;
     1018        }
     1019
     1020        $translations = file_get_contents( $file );
     1021
     1022        /**
     1023         * Filters script translations for the given file, script handle and text domain.
     1024         *
     1025         * @since 5.0.2
     1026         *
     1027         * @param string $translations JSON-encoded translation data.
     1028         * @param string $file         Path to the translation file that was loaded.
     1029         * @param string $handle       Name of the script to register a translation domain to.
     1030         * @param string $domain       The text domain.
     1031         */
     1032        return apply_filters( 'load_script_translations', $translations, $file, $handle, $domain );
     1033}
     1034
     1035/**
    9761036 * Loads plugin and theme textdomains just-in-time.
    9771037 *
    9781038 * When a textdomain is encountered for the first time, we try to load
     
    14041464
    14051465/**
    14061466 * Determines whether the current locale is right-to-left (RTL).
    1407  * 
     1467 *
    14081468 * For more information on this and similar theme functions, check out
    1409  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 
     1469 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
    14101470 * Conditional Tags} article in the Theme Developer Handbook.
    14111471 *
    14121472 * @since 3.0.0