Changeset 44169 for trunk/src/wp-includes/class.wp-scripts.php
- Timestamp:
- 12/14/2018 05:51:31 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43825,43828,43859,43898
- Property svn:mergeinfo changed
-
trunk/src/wp-includes/class.wp-scripts.php
r43583 r44169 331 331 } 332 332 333 $translations = $this->print_translations( $handle, false ); 334 if ( $translations ) { 335 $translations = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $translations ); 336 } 337 333 338 if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { 334 339 $src = $this->base_url . $src; … … 346 351 } 347 352 348 $tag = "{$ cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}";353 $tag = "{$translations}{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}"; 349 354 350 355 /** … … 489 494 490 495 return parent::set_group( $handle, $recursion, $grp ); 496 } 497 498 /** 499 * Sets a translation textdomain. 500 * 501 * @since 5.0.0 502 * 503 * @param string $handle Name of the script to register a translation domain to. 504 * @param string $domain The textdomain. 505 * @param string $path Optional. The full file path to the directory containing translation files. 506 * 507 * @return bool True if the textdomain was registered, false if not. 508 */ 509 public function set_translations( $handle, $domain, $path = null ) { 510 if ( ! isset( $this->registered[ $handle ] ) ) { 511 return false; 512 } 513 514 /** @var \_WP_Dependency $obj */ 515 $obj = $this->registered[ $handle ]; 516 517 if ( ! in_array( 'wp-i18n', $obj->deps, true ) ) { 518 $obj->deps[] = 'wp-i18n'; 519 } 520 return $obj->set_translations( $domain, $path ); 521 } 522 523 /** 524 * Prints translations set for a specific handle. 525 * 526 * @since 5.0.0 527 * 528 * @param string $handle Name of the script to add the inline script to. Must be lowercase. 529 * @param bool $echo Optional. Whether to echo the script instead of just returning it. 530 * Default true. 531 * @return string|false Script on success, false otherwise. 532 */ 533 public function print_translations( $handle, $echo = true ) { 534 if ( ! isset( $this->registered[ $handle ] ) || empty( $this->registered[ $handle ]->textdomain ) ) { 535 return false; 536 } 537 538 $domain = $this->registered[ $handle ]->textdomain; 539 $path = $this->registered[ $handle ]->translations_path; 540 541 $json_translations = load_script_textdomain( $handle, $domain, $path ); 542 543 if ( ! $json_translations ) { 544 // Register empty locale data object to ensure the domain still exists. 545 $json_translations = '{ "locale_data": { "messages": { "": {} } } }'; 546 } 547 548 $output = '(function( translations ){' . 549 'wp.i18n.setLocaleData( translations.locale_data, "' . $domain . '" );' . 550 '})(' . $json_translations . ');'; 551 552 if ( $echo ) { 553 printf( "<script type='text/javascript'>\n%s\n</script>\n", $output ); 554 } 555 556 return $output; 491 557 } 492 558
Note: See TracChangeset
for help on using the changeset viewer.