WP_Scripts::print_translations() WordPress Method
The print_translations() method is used to print translation strings for a given script. This is useful for debugging purposes.
WP_Scripts::print_translations( string $handle, bool $display = true ) #
Prints translations set for a specific handle.
Parameters
- $handle
(string)(Required)Name of the script to add the inline script to. Must be lowercase.
- $display
(bool)(Optional) Whether to print the script instead of just returning it.
Default value: true
Return
(string|false) Script on success, false otherwise.
Source
File: wp-includes/class.wp-scripts.php
public function print_translations( $handle, $display = true ) { if ( ! isset( $this->registered[ $handle ] ) || empty( $this->registered[ $handle ]->textdomain ) ) { return false; } $domain = $this->registered[ $handle ]->textdomain; $path = $this->registered[ $handle ]->translations_path; $json_translations = load_script_textdomain( $handle, $domain, $path ); if ( ! $json_translations ) { return false; } $output = <<<JS ( function( domain, translations ) { var localeData = translations.locale_data[ domain ] || translations.locale_data.messages; localeData[""].domain = domain; wp.i18n.setLocaleData( localeData, domain ); } )( "{$domain}", {$json_translations} ); JS; if ( $display ) { printf( "<script%s id='%s-js-translations'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $output ); } return $output; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |