Changeset 43859 for branches/5.0/src/wp-includes/class.wp-scripts.php
- Timestamp:
- 11/01/2018 01:50:59 PM (7 years ago)
- File:
-
- 1 edited
-
branches/5.0/src/wp-includes/class.wp-scripts.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/class.wp-scripts.php
r43825 r43859 326 326 } 327 327 328 $translations = $this->print_translations( $handle, false ); 329 if ( $translations ) { 330 $translations = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $translations ); 331 } 332 328 333 if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { 329 334 $src = $this->base_url . $src; … … 339 344 return true; 340 345 341 $tag = "{$ cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}";346 $tag = "{$translations}{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}"; 342 347 343 348 /** … … 479 484 480 485 /** 481 * Registera translation textdomain.486 * Sets a translation textdomain. 482 487 * 483 488 * @since 5.0.0 … … 494 499 } 495 500 496 $json_translations = load_script_textdomain( $handle, $domain, $path );497 498 if ( ! $json_translations ) {499 return false;500 }501 502 501 /** @var \_WP_Dependency $obj */ 503 502 $obj = $this->registered[ $handle ]; 504 $obj->deps[] = 'wp-i18n'; 505 506 return $this->add_inline_script( 507 $handle, 508 '(function( translations ){' . 509 'wp.i18n.setLocaleData( translations.locale_data, "' . $domain . '" );' . 510 '})(' . $json_translations . ');', 511 'before' 512 ); 503 504 if ( ! in_array( 'wp-i18n', $obj->deps, true ) ) { 505 $obj->deps[] = 'wp-i18n'; 506 } 507 return $obj->set_translations( $domain, $path ); 508 } 509 510 /** 511 * Prints translations set for a specific handle. 512 * 513 * @since 5.0.0 514 * 515 * @param string $handle Name of the script to add the inline script to. Must be lowercase. 516 * @param bool $echo Optional. Whether to echo the script instead of just returning it. 517 * Default true. 518 * @return string|false Script on success, false otherwise. 519 */ 520 public function print_translations( $handle, $echo = true ) { 521 if ( ! isset( $this->registered[ $handle ] ) || empty( $this->registered[ $handle ]->textdomain ) ) { 522 return false; 523 } 524 525 $domain = $this->registered[ $handle ]->textdomain; 526 $path = $this->registered[ $handle ]->translations_path; 527 528 $json_translations = load_script_textdomain( $handle, $domain, $path ); 529 530 if ( ! $json_translations ) { 531 return false; 532 } 533 534 $output = '(function( translations ){' . 535 'wp.i18n.setLocaleData( translations.locale_data, "' . $domain . '" );' . 536 '})(' . $json_translations . ');'; 537 538 if ( $echo ) { 539 printf( "<script type='text/javascript'>\n%s\n</script>\n", $output ); 540 } 541 542 return $output; 513 543 } 514 544
Note: See TracChangeset
for help on using the changeset viewer.