Ticket #45425: 45425.2.diff
File 45425.2.diff, 4.8 KB (added by , 6 years ago) |
---|
-
src/wp-includes/l10n.php
870 870 } 871 871 872 872 /** 873 * Load the script translated strings.873 * Loads the script translated strings. 874 874 * 875 875 * @see WP_Scripts::set_translations() 876 * @link https://core.trac.wordpress.org/ticket/45103876 * 877 877 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 878 878 * 879 879 * @since 5.0.0 880 * @since 5.0.2 Uses load_script_translations() to load translations. 880 881 * 881 882 * @param string $handle Name of the script to register a translation domain to. 882 883 * @param string $domain The textdomain. … … 899 900 $file_base = $domain === 'default' ? $locale : $domain . '-' . $locale; 900 901 $handle_filename = $file_base . '-' . $handle . '.json'; 901 902 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 ); 903 904 } 904 905 905 906 $obj = $wp_scripts->registered[ $handle ]; … … 953 954 954 955 // If the source is not from WP. 955 956 if ( false === $relative ) { 956 return false;957 return load_script_translations( false, $handle, $domain ); 957 958 } 958 959 959 960 // Translations are always based on the unminified filename. … … 963 964 964 965 $md5_filename = $file_base . '-' . md5( $relative ) . '.json'; 965 966 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 ); 967 968 } 968 969 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 ); 970 971 } 971 972 972 return false;973 return load_script_translations( false, $handle, $domain ); 973 974 } 974 975 975 976 /** 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 */ 986 function 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 /** 976 1036 * Loads plugin and theme textdomains just-in-time. 977 1037 * 978 1038 * When a textdomain is encountered for the first time, we try to load … … 1404 1464 1405 1465 /** 1406 1466 * Determines whether the current locale is right-to-left (RTL). 1407 * 1467 * 1408 1468 * 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/ 1410 1470 * Conditional Tags} article in the Theme Developer Handbook. 1411 1471 * 1412 1472 * @since 3.0.0