| 954 | | return false; |
| | 954 | return load_script_translation( false, $handle, $domain ); |
| | 955 | } |
| | 956 | |
| | 957 | /** |
| | 958 | * Load the translated strings for the given script handle and textdomain. |
| | 959 | * |
| | 960 | * @since 5.0.0 |
| | 961 | * |
| | 962 | * @param string|false $file Path to the translation file to load. False if there isn't one. |
| | 963 | * @param string $handle Name of the script to register a translation domain to. |
| | 964 | * @param string $domain The textdomain. |
| | 965 | * @return string|false The JSON-encoded translated strings for the given script handle and textdomain. False if there are none. |
| | 966 | */ |
| | 967 | function load_script_translation( $file, $handle, $domain ) { |
| | 968 | /** |
| | 969 | * Pre-filters script translations for the given file, script handle and text domain. |
| | 970 | * |
| | 971 | * Returning a non-null value allows to override the default logic, effectively short-circuiting the function. |
| | 972 | * |
| | 973 | * @since 5.0.0 |
| | 974 | * |
| | 975 | * @param string|false $translations JSON-encoded translation data. Default null. |
| | 976 | * @param string|false $file Path to the translation file to load. False if there isn't one. |
| | 977 | * @param string $handle Name of the script to register a translation domain to. |
| | 978 | * @param string $domain The textdomain. |
| | 979 | */ |
| | 980 | $translations = apply_filters( 'pre_load_script_translation', null, $file, $handle, $domain ); |
| | 981 | |
| | 982 | if ( null !== $translations ) { |
| | 983 | return $translations; |
| | 984 | } |
| | 985 | |
| | 986 | /** |
| | 987 | * Filters the file path for loading script translations for the given script handle and textdomain. |
| | 988 | * |
| | 989 | * @since 5.0.0 |
| | 990 | * |
| | 991 | * @param string|false $file Path to the translation file to load. False if there isn't one. |
| | 992 | * @param string $handle Name of the script to register a translation domain to. |
| | 993 | * @param string $domain The textdomain. |
| | 994 | */ |
| | 995 | $file = apply_filters( 'load_script_textdomain_file', $file, $handle, $domain ); |
| | 996 | |
| | 997 | if ( ! $file || ! is_readable( $file ) ) { |
| | 998 | return false; |
| | 999 | } |
| | 1000 | |
| | 1001 | $translations = file_get_contents( $file ); |
| | 1002 | |
| | 1003 | /** |
| | 1004 | * Filters script translations for the given file, script handle and text domain. |
| | 1005 | * |
| | 1006 | * @since 5.0.0 |
| | 1007 | * |
| | 1008 | * @param string $translations JSON-encoded translation data |
| | 1009 | * @param string $file Path to the translation file that was loaded. |
| | 1010 | * @param string $handle Name of the script to register a translation domain to. |
| | 1011 | * @param string $domain The textdomain. |
| | 1012 | */ |
| | 1013 | return apply_filters( 'load_script_translation', $translations, $file, $handle, $domain ); |