Changeset 60728
- Timestamp:
- 09/11/2025 10:11:40 AM (4 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n.php
r59719 r60728 1135 1135 * @see WP_Scripts::set_translations() 1136 1136 * 1137 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 1138 * 1137 1139 * @param string $handle Name of the script to register a translation domain to. 1138 1140 * @param string $domain Optional. Text domain. Default 'default'. … … 1142 1144 */ 1143 1145 function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { 1146 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 1147 global $wp_textdomain_registry; 1148 1144 1149 $wp_scripts = wp_scripts(); 1145 1150 … … 1148 1153 } 1149 1154 1150 $path = untrailingslashit( $path );1151 1155 $locale = determine_locale(); 1156 1157 if ( ! $path ) { 1158 $path = $wp_textdomain_registry->get( $domain, $locale ); 1159 } 1160 1161 $path = untrailingslashit( $path ); 1152 1162 1153 1163 // If a path was given and the handle file exists simply return it. -
trunk/tests/phpunit/tests/dependencies/scripts.php
r60719 r60728 2629 2629 ); 2630 2630 $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js' id='test-example-js'></script>\n"; 2631 2632 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); 2633 } 2634 2635 /** 2636 * @ticket 63944 2637 */ 2638 public function test_wp_set_script_translations_uses_registered_domainpath_for_plugin() { 2639 global $wp_textdomain_registry; 2640 2641 wp_register_script( 'wp-i18n', '/wp-includes/js/dist/wp-i18n.js', array(), null ); 2642 wp_enqueue_script( 'domain-path-plugin', '/wp-content/plugins/my-plugin/js/script.js', array(), null ); 2643 2644 // Simulate a plugin declaring DomainPath: /languages by registering a custom path. 2645 $wp_textdomain_registry->set_custom_path( 'internationalized-plugin', DIR_TESTDATA . '/languages/plugins' ); 2646 wp_set_script_translations( 'domain-path-plugin', 'internationalized-plugin' ); 2647 2648 $expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js' id='wp-i18n-js'></script>\n"; 2649 $expected .= str_replace( 2650 array( 2651 '__DOMAIN__', 2652 '__HANDLE__', 2653 '__JSON_TRANSLATIONS__', 2654 ), 2655 array( 2656 'internationalized-plugin', 2657 'domain-path-plugin', 2658 file_get_contents( DIR_TESTDATA . '/languages/plugins/internationalized-plugin-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' ), 2659 ), 2660 $this->wp_scripts_print_translations_output 2661 ); 2662 $expected .= "<script type='text/javascript' src='/wp-content/plugins/my-plugin/js/script.js' id='domain-path-plugin-js'></script>\n"; 2663 2664 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); 2665 } 2666 2667 /** 2668 * @ticket 63944 2669 * 2670 * Ensure human-readable script translation filenames are found when a 2671 * textdomain has a custom DomainPath registered and no explicit $path is passed. 2672 */ 2673 public function test_wp_set_script_translations_prefers_human_readable_filename_in_registered_domainpath() { 2674 global $wp_textdomain_registry; 2675 2676 wp_register_script( 'wp-i18n', '/wp-includes/js/dist/wp-i18n.js', array(), null ); 2677 wp_enqueue_script( 'script-handle', '/wp-admin/js/script.js', array(), null ); 2678 2679 // Register the admin textdomain path and use the admin translations file for this script-handle test. 2680 $wp_textdomain_registry->set_custom_path( 'admin', DIR_TESTDATA . '/languages' ); 2681 wp_set_script_translations( 'script-handle', 'admin' ); 2682 2683 $expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js' id='wp-i18n-js'></script>\n"; 2684 $expected .= str_replace( 2685 array( 2686 '__DOMAIN__', 2687 '__HANDLE__', 2688 '__JSON_TRANSLATIONS__', 2689 ), 2690 array( 2691 'admin', 2692 'script-handle', 2693 file_get_contents( DIR_TESTDATA . '/languages/admin-en_US-script-handle.json' ), 2694 ), 2695 $this->wp_scripts_print_translations_output 2696 ); 2697 $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js' id='script-handle-js'></script>\n"; 2631 2698 2632 2699 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
Note: See TracChangeset for help on using the changeset viewer.