Ticket #39210: 39210.diff
File 39210.diff, 12.5 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-locale-switcher.php
187 187 * @access private 188 188 * 189 189 * @global Mo[] $l10n An array of all currently loaded text domains. 190 * @global array $l10n_paths An array of all plugin and theme text domains and the paths from which they've been loaded. 190 191 * 191 192 * @param string $locale The locale to load translations for. 192 193 */ 193 194 private function load_translations( $locale ) { 194 global $l10n ;195 global $l10n, $l10n_paths; 195 196 196 $domains = $l10n ? array_keys( $l10n ) : array(); 197 $loaded_domains = $l10n ? array_keys( $l10n ) : array(); 198 $domains_from_paths = $l10n_paths ? array_keys( $l10n_paths ) : array(); 197 199 200 $domains = array_unique( array_merge( $loaded_domains, $domains_from_paths ) ); 201 198 202 load_default_textdomain( $locale ); 199 203 200 204 foreach ( $domains as $domain ) { -
src/wp-includes/l10n.php
695 695 * @since 1.5.0 696 696 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. 697 697 * 698 * @global array $l10n_paths An array of all plugin and theme text domains and the paths 699 * from which they've been loaded. 700 * 698 701 * @param string $domain Unique identifier for retrieving translated strings 699 702 * @param string $deprecated Optional. Use the $plugin_rel_path parameter instead. Default false. 700 703 * @param string $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides. … … 702 705 * @return bool True when textdomain is successfully loaded, false otherwise. 703 706 */ 704 707 function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { 708 global $l10n_paths; 709 705 710 /** 706 711 * Filters a plugin's locale. 707 712 * … … 728 733 $path = WP_PLUGIN_DIR; 729 734 } 730 735 736 $l10n_paths[ $domain ] = array( 'type' => 'plugin', 'path' => str_replace( WP_PLUGIN_DIR . '/', '', $path ) ); 737 731 738 return load_textdomain( $domain, $path . '/' . $mofile ); 732 739 } 733 740 … … 737 744 * @since 3.0.0 738 745 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. 739 746 * 747 * @global array $l10n_paths An array of all plugin and theme text domains and the paths from which 748 * they've been loaded. 749 * 740 750 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 741 751 * @param string $mu_plugin_rel_path Optional. Relative to `WPMU_PLUGIN_DIR` directory in which the .mo 742 752 * file resides. Default empty string. … … 743 753 * @return bool True when textdomain is successfully loaded, false otherwise. 744 754 */ 745 755 function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 756 global $l10n_paths; 757 746 758 /** This filter is documented in wp-includes/l10n.php */ 747 759 $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); 748 760 … … 754 766 } 755 767 756 768 $path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) ); 769 $l10n_paths[ $domain ] = array( 'type' => 'muplugin', 'path' => str_replace( WPMU_PLUGIN_DIR . '/', '', $path ) ); 757 770 758 771 return load_textdomain( $domain, $path . '/' . $mofile ); 759 772 } … … 769 782 * @since 1.5.0 770 783 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. 771 784 * 772 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 773 * @param string $path Optional. Path to the directory containing the .mo file. 774 * Default false. 785 * @global array $l10n_paths An array of all plugin and theme text domains and the paths from which 786 * they've been loaded. 787 * 788 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 789 * @param bool|string $path Optional. Path to the directory containing the .mo file. 790 * Default false. 775 791 * @return bool True when textdomain is successfully loaded, false otherwise. 776 792 */ 777 793 function load_theme_textdomain( $domain, $path = false ) { 794 global $l10n_paths; 778 795 /** 779 796 * Filters a theme's locale. 780 797 * … … 796 813 $path = get_template_directory(); 797 814 } 798 815 816 $l10n_paths[ $domain ] = array( 'type' => 'theme', 'path' => $path ); 817 799 818 return load_textdomain( $domain, $path . '/' . $locale . '.mo' ); 800 819 } 801 820 … … 837 856 * @return bool True when the textdomain is successfully loaded, false otherwise. 838 857 */ 839 858 function _load_textdomain_just_in_time( $domain ) { 840 global $l10n_unloaded ;859 global $l10n_unloaded, $l10n_paths; 841 860 842 861 $l10n_unloaded = (array) $l10n_unloaded; 843 862 … … 938 957 * @since 2.8.0 939 958 * 940 959 * @global array $l10n 960 * @global array $l10n_paths An array of all plugin and theme text domains and the paths 961 * from which they've been loaded. 941 962 * 942 963 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 964 * 943 965 * @return Translations|NOOP_Translations A Translations instance. 944 966 */ 945 967 function get_translations_for_domain( $domain ) { 946 global $l10n; 968 global $l10n, $l10n_paths; 969 947 970 if ( isset( $l10n[ $domain ] ) || ( _load_textdomain_just_in_time( $domain ) && isset( $l10n[ $domain ] ) ) ) { 948 971 return $l10n[ $domain ]; 949 972 } 950 973 974 if ( isset( $l10n_paths[ $domain ] ) ) { 975 $loaded = call_user_func( 'load_' . $l10n_paths[ $domain ]['type'] . '_textdomain', $domain, false, $l10n_paths[ $domain ]['path'] ); 976 977 if ( $loaded && isset( $l10n[ $domain ] ) ) { 978 return $l10n[ $domain ]; 979 } 980 } 981 951 982 static $noop_translations = null; 952 983 if ( null === $noop_translations ) { 953 984 $noop_translations = new NOOP_Translations; -
tests/phpunit/data/plugins/custom-internationalized-plugin/custom-internationalized-plugin.php
1 <?php 2 /* 3 Plugin Name: Custom Dummy Plugin 4 Plugin URI: https://wordpress.org/ 5 Description: For testing purposes only. 6 Version: 1.0.0 7 Text Domain: custom-internationalized-plugin 8 */ 9 10 load_plugin_textdomain( 'custom-internationalized-plugin', false, basename( dirname( __FILE__ ) ) . '/languages' ); 11 12 function custom_i18n_plugin_test() { 13 return __( 'This is a dummy plugin', 'custom-internationalized-plugin' ); 14 } -
tests/phpunit/data/plugins/custom-internationalized-plugin/languages/custom-internationalized-plugin-de_DE.mo
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
-
tests/phpunit/data/plugins/custom-internationalized-plugin/languages/custom-internationalized-plugin-de_DE.po
Property changes on: tests/phpunit/data/plugins/custom-internationalized-plugin/languages/custom-internationalized-plugin-de_DE.mo ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property
1 msgid "" 2 msgstr "" 3 "Project-Id-Version: \n" 4 "POT-Creation-Date: 2015-12-31 16:31+0100\n" 5 "PO-Revision-Date: 2016-10-26 00:02+0200\n" 6 "Language: de_DE\n" 7 "MIME-Version: 1.0\n" 8 "Content-Type: text/plain; charset=UTF-8\n" 9 "Content-Transfer-Encoding: 8bit\n" 10 "X-Generator: Poedit 1.8.10\n" 11 "X-Poedit-Basepath: .\n" 12 "Plural-Forms: nplurals=2; plural=(n != 1);\n" 13 "X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;" 14 "_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;" 15 "esc_html_x:1,2c\n" 16 "X-Textdomain-Support: yes\n" 17 "X-Poedit-SearchPath-0: .\n" 18 19 #: internationalized-plugin.php:11 20 msgid "This is a dummy plugin" 21 msgstr "Das ist ein Dummy Plugin" -
tests/phpunit/data/plugins/custom-internationalized-plugin/languages/custom-internationalized-plugin-en_GB.mo
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
-
tests/phpunit/data/plugins/custom-internationalized-plugin/languages/custom-internationalized-plugin-en_GB.po
Property changes on: tests/phpunit/data/plugins/custom-internationalized-plugin/languages/custom-internationalized-plugin-en_GB.mo ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property
1 msgid "" 2 msgstr "" 3 "Project-Id-Version: \n" 4 "POT-Creation-Date: 2015-12-31 16:31+0100\n" 5 "PO-Revision-Date: 2016-12-15 15:26+0200\n" 6 "Language: en_GB\n" 7 "MIME-Version: 1.0\n" 8 "Content-Type: text/plain; charset=UTF-8\n" 9 "Content-Transfer-Encoding: 8bit\n" 10 "X-Generator: Poedit 1.8.9\n" 11 "X-Poedit-Basepath: .\n" 12 "Plural-Forms: nplurals=2; plural=(n != 1);\n" 13 "X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;" 14 "_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;" 15 "esc_html_x:1,2c\n" 16 "X-Textdomain-Support: yes\n" 17 "Last-Translator: \n" 18 "Language-Team: \n" 19 "X-Poedit-SearchPath-0: .\n" 20 21 #: internationalized-plugin.php:11 22 msgid "This is a dummy plugin" 23 msgstr "This is a wally plugin" -
tests/phpunit/includes/bootstrap.php
30 30 define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' ); 31 31 32 32 define( 'WP_LANG_DIR', DIR_TESTDATA . '/languages' ); 33 define( 'WP_PLUGIN_DIR', DIR_TESTDATA . '/plugins' ); 33 34 34 35 if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) 35 36 define( 'WP_TESTS_FORCE_KNOWN_BUGS', false ); -
tests/phpunit/tests/l10n/localeSwitcher.php
382 382 $this->assertSame( 'This is a dummy plugin', $expected ); 383 383 } 384 384 385 public function test_switch_reloads_translations_outside_wplang( ){ 386 require_once DIR_TESTDATA . '/plugins/custom-internationalized-plugin/custom-internationalized-plugin.php'; 387 388 $expected = custom_i18n_plugin_test(); 389 $this->assertSame( 'This is a dummy plugin', $expected ); 390 391 switch_to_locale( 'en_GB'); 392 switch_to_locale( 'de_DE'); 393 $expected = custom_i18n_plugin_test(); 394 $this->assertSame( 'Das ist ein Dummy Plugin', $expected ); 395 396 restore_previous_locale(); 397 $expected = custom_i18n_plugin_test(); 398 $this->assertSame( 'This is a wally plugin', $expected ); 399 400 restore_current_locale(); 401 } 402 385 403 public function filter_locale() { 386 404 return 'es_ES'; 387 405 }