Ticket #39210: 39210.3.diff
File 39210.3.diff, 3.3 KB (added by , 6 years ago) |
---|
-
wp-includes/class-wp-locale-switcher.php
class WP_Locale_Switcher { 188 188 * 189 189 * @param string $locale The locale to load translations for. 190 190 */ 191 191 private function load_translations( $locale ) { 192 192 global $l10n; 193 193 194 194 $domains = $l10n ? array_keys( $l10n ) : array(); 195 195 196 196 load_default_textdomain( $locale ); 197 197 198 198 foreach ( $domains as $domain ) { 199 199 if ( 'default' === $domain ) { 200 200 continue; 201 201 } 202 202 203 unload_textdomain( $domain );203 unload_textdomain( $domain, true ); 204 204 get_translations_for_domain( $domain ); 205 205 } 206 206 } 207 207 208 208 /** 209 209 * Changes the site's locale to the given one. 210 210 * 211 211 * Loads the translations, changes the global `$wp_locale` object and updates 212 212 * all post type labels. 213 213 * 214 214 * @since 4.7.0 215 215 * 216 216 * @global WP_Locale $wp_locale The WordPress date and time locale object. 217 217 * 218 218 * @param string $locale The locale to change to. -
wp-includes/l10n.php
function load_textdomain( $domain, $mofi 662 662 unset( $l10n_unloaded[ $domain ] ); 663 663 664 664 $l10n[ $domain ] = &$mo; 665 665 666 666 return true; 667 667 } 668 668 669 669 /** 670 670 * Unload translations for a text domain. 671 671 * 672 672 * @since 3.0.0 673 673 * 674 674 * @global MO[] $l10n An array of all currently loaded text domains. 675 675 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. 676 676 * 677 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 677 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 678 * @param bool $reloadable Whether this textdomain should be loaded JIT again. 678 679 * @return bool Whether textdomain was unloaded. 679 680 */ 680 function unload_textdomain( $domain ) {681 function unload_textdomain( $domain, $reloadable = false ) { 681 682 global $l10n, $l10n_unloaded; 682 683 683 684 $l10n_unloaded = (array) $l10n_unloaded; 684 685 685 686 /** 686 687 * Filters whether to override the text domain unloading. 687 688 * 688 689 * @since 3.0.0 689 690 * 690 691 * @param bool $override Whether to override the text domain unloading. Default false. 691 692 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 692 693 */ 693 694 $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain ); 694 695 695 696 if ( $plugin_override ) { 696 $l10n_unloaded[ $domain ] = true; 697 if ( ! $reloadable ) { 698 $l10n_unloaded[ $domain ] = true; 699 } 697 700 698 701 return true; 699 702 } 700 703 701 704 /** 702 705 * Fires before the text domain is unloaded. 703 706 * 704 707 * @since 3.0.0 705 708 * 706 709 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 707 710 */ 708 711 do_action( 'unload_textdomain', $domain ); 709 712 710 713 if ( isset( $l10n[ $domain ] ) ) { 711 714 unset( $l10n[ $domain ] ); 712 715 713 $l10n_unloaded[ $domain ] = true; 716 if ( ! $reloadable ) { 717 $l10n_unloaded[ $domain ] = true; 718 } 714 719 715 720 return true; 716 721 } 717 722 718 723 return false; 719 724 } 720 725 721 726 /** 722 727 * Load default translated strings based on locale. 723 728 * 724 729 * Loads the .mo file in WP_LANG_DIR constant path from WordPress root. 725 730 * The translated (.mo) file is named based on the locale. 726 731 * 727 732 * @see load_textdomain() 728 733 *