Changeset 44232 for branches/5.0
- Timestamp:
- 12/16/2018 03:53:34 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/l10n.php
r44209 r44232 871 871 872 872 /** 873 * Load the script translated strings. 873 * Loads the script translated strings. 874 * 875 * @since 5.0.0 876 * @since 5.0.2 Uses load_script_translations() to load translation data. 874 877 * 875 878 * @see WP_Scripts::set_translations() 876 * @link https://core.trac.wordpress.org/ticket/45103877 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.878 *879 * @since 5.0.0880 879 * 881 880 * @param string $handle Name of the script to register a translation domain to. 882 * @param string $domain The text domain.881 * @param string $domain The text domain. 883 882 * @param string $path Optional. The full file path to the directory containing translation files. 884 883 * … … 887 886 */ 888 887 function load_script_textdomain( $handle, $domain, $path = null ) { 889 global $wp_scripts;888 $wp_scripts = wp_scripts(); 890 889 891 890 if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { … … 900 899 $handle_filename = $file_base . '-' . $handle . '.json'; 901 900 if ( $path && file_exists( $path . '/' . $handle_filename ) ) { 902 return file_get_contents( $path . '/' . $handle_filename);901 return load_script_translations( $path . '/' . $handle_filename, $handle, $domain ); 903 902 } 904 903 … … 954 953 // If the source is not from WP. 955 954 if ( false === $relative ) { 956 return false;955 return load_script_translations( false, $handle, $domain ); 957 956 } 958 957 … … 964 963 $md5_filename = $file_base . '-' . md5( $relative ) . '.json'; 965 964 if ( $path && file_exists( $path . '/' . $md5_filename ) ) { 966 return file_get_contents( $path . '/' . $md5_filename);965 return load_script_translations( $path . '/' . $md5_filename, $handle, $domain ); 967 966 } 968 967 if ( file_exists( $languages_path . '/' . $md5_filename ) ) { 969 return file_get_contents( $languages_path . '/' . $md5_filename ); 970 } 971 972 return false; 968 return load_script_translations( $languages_path . '/' . $md5_filename, $handle, $domain ); 969 } 970 971 return load_script_translations( false, $handle, $domain ); 972 } 973 974 /** 975 * Loads the translation data for the given script handle and text domain. 976 * 977 * @since 5.0.2 978 * 979 * @param string|false $file Path to the translation file to load. False if there isn't one. 980 * @param string $handle Name of the script to register a translation domain to. 981 * @param string $domain The text domain. 982 * @return string|false The JSON-encoded translated strings for the given script handle and text domain. False if there are none. 983 */ 984 function load_script_translations( $file, $handle, $domain ) { 985 /** 986 * Pre-filters script translations for the given file, script handle and text domain. 987 * 988 * Returning a non-null value allows to override the default logic, effectively short-circuiting the function. 989 * 990 * @since 5.0.2 991 * 992 * @param string|false $translations JSON-encoded translation data. Default null. 993 * @param string|false $file Path to the translation file to load. False if there isn't one. 994 * @param string $handle Name of the script to register a translation domain to. 995 * @param string $domain The text domain. 996 */ 997 $translations = apply_filters( 'pre_load_script_translations', null, $file, $handle, $domain ); 998 999 if ( null !== $translations ) { 1000 return $translations; 1001 } 1002 1003 /** 1004 * Filters the file path for loading script translations for the given script handle and text domain. 1005 * 1006 * @since 5.0.2 1007 * 1008 * @param string|false $file Path to the translation file to load. False if there isn't one. 1009 * @param string $handle Name of the script to register a translation domain to. 1010 * @param string $domain The text domain. 1011 */ 1012 $file = apply_filters( 'load_script_translation_file', $file, $handle, $domain ); 1013 1014 if ( ! $file || ! is_readable( $file ) ) { 1015 return false; 1016 } 1017 1018 $translations = file_get_contents( $file ); 1019 1020 /** 1021 * Filters script translations for the given file, script handle and text domain. 1022 * 1023 * @since 5.0.2 1024 * 1025 * @param string $translations JSON-encoded translation data. 1026 * @param string $file Path to the translation file that was loaded. 1027 * @param string $handle Name of the script to register a translation domain to. 1028 * @param string $domain The text domain. 1029 */ 1030 return apply_filters( 'load_script_translations', $translations, $file, $handle, $domain ); 973 1031 } 974 1032 … … 1405 1463 /** 1406 1464 * Determines whether the current locale is right-to-left (RTL). 1407 * 1465 * 1408 1466 * For more information on this and similar theme functions, check out 1409 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 1467 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 1410 1468 * Conditional Tags} article in the Theme Developer Handbook. 1411 1469 *
Note: See TracChangeset
for help on using the changeset viewer.