[ WordPress.org  ](https://wordpress.org/)

  * [ News  ](https://wordpress.org/news/)
  * [ Showcase  ](https://wordpress.org/showcase/)
  * [ Hosting  ](https://wordpress.org/hosting/)
  * Extend 
    * [ Themes  ](https://wordpress.org/themes/)
    * [ Plugins  ](https://wordpress.org/plugins/)
    * [ Patterns  ](https://wordpress.org/patterns/)
    * [ Blocks  ](https://wordpress.org/blocks/)
    * [ Openverse  ↗  ︎  ](https://openverse.org/)
  * Learn 
    * [ Learn WordPress  ](https://learn.wordpress.org/)
    * [ Documentation  ](https://wordpress.org/documentation/)
    * [ Forums  ](https://wordpress.org/support/forums/)
    * [ Developers  ](https://developer.wordpress.org/)
    * [ WordPress.tv  ↗  ︎  ](https://wordpress.tv/)
  * Community 
    * [ Make WordPress  ](https://make.wordpress.org/)
    * [ Photo Directory  ](https://wordpress.org/photos/)
    * [ Five for the Future  ](https://wordpress.org/five-for-the-future/)
    * [ Events  ](https://events.wordpress.org/)
    * [ Job Board  ↗  ︎  ](https://jobs.wordpress.net/)
  * About 
    * [ About WordPress  ](https://wordpress.org/about/)
    * [ Enterprise  ](https://wordpress.org/enterprise/)
    * [ Gutenberg  ↗  ︎  ](https://wordpress.org/gutenberg/)
    * [ Swag Store  ↗  ︎  ](https://mercantile.wordpress.org/)
  * [ Get WordPress  ](https://wordpress.org/download/)

Search in WordPress.org

[ Get WordPress ](https://wordpress.org/download/)

[ WordPress.org  ](https://wordpress.org/)

[ WordPress Developer Resources ](https://developer.wordpress.org)

WP_Scripts::print_translations()

  * [ Developer Blog  ](https://developer.wordpress.org/news/)
  * [ Code Reference  ](https://developer.wordpress.org/reference/)
  * [ WP-CLI Commands  ](https://developer.wordpress.org/cli/commands/)

  * [ Developer Blog  ](https://developer.wordpress.org/news/)
  * [ Code Reference  ](https://developer.wordpress.org/reference/)
  * [ WP-CLI Commands  ](https://developer.wordpress.org/cli/commands/)

[ Home ](https://developer.wordpress.org) [ Reference
](https://developer.wordpress.org/reference/) [ Classes
](https://developer.wordpress.org/reference/classes/) [ WP_Scripts
](https://developer.wordpress.org/reference/classes/wp_scripts/)
WP_Scripts::print_translations()

Search

#  WP_Scripts::print_translations(  string  $handle  ,  bool  $display  =
true  ):  string|false

##  In this article

Table of Contents

  * Parameters 
  * Return 
  * Source 
  * Related 
  * Changelog 

↑  Back to top

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: ` true `

##  Return

string|false  Script on success, false otherwise.

##  Source

    
    
    	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   = '';
    
    		if ( isset( $this->registered[ $handle ]->translations_path ) ) {
    			$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 ) {
    			wp_print_inline_script_tag( $output, array( 'id' => "{$handle}-js-translations" ) );
    		}
    
    		return $output;
    	}
    

[ View all references ](https://developer.wordpress.org/reference/