Changeset 38961
- Timestamp:
- 10/26/2016 03:35:58 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ms.php
r38876 r38961 273 273 update_option( 'adminhash', $new_admin_email ); 274 274 275 $switched_locale = switch_to_locale( get_user_locale() ); 276 275 277 /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ 276 278 $email_text = __( 'Howdy ###USERNAME###, … … 316 318 317 319 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); 320 321 if ( $switched_locale ) { 322 restore_previous_locale(); 323 } 318 324 } 319 325 … … 353 359 ); 354 360 update_user_meta( $current_user->ID, '_new_email', $new_user_email ); 361 362 $switched_locale = switch_to_locale( get_user_locale() ); 355 363 356 364 /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ … … 396 404 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); 397 405 $_POST['email'] = $current_user->user_email; 406 407 if ( $switched_locale ) { 408 restore_previous_locale(); 409 } 398 410 } 399 411 } -
trunk/src/wp-admin/ms-delete-site.php
r38822 r38961 43 43 $url_delete = esc_url( admin_url( 'ms-delete-site.php?h=' . $hash ) ); 44 44 45 $switched_locale = switch_to_locale( get_locale() ); 46 45 47 /* translators: Do not translate USERNAME, URL_DELETE, SITE_NAME: those are placeholders. */ 46 48 $content = __( "Howdy ###USERNAME###, … … 74 76 75 77 wp_mail( get_option( 'admin_email' ), "[ " . wp_specialchars_decode( get_option( 'blogname' ) ) . " ] ".__( 'Delete My Site' ), $content ); 78 79 if ( $switched_locale ) { 80 restore_previous_locale(); 81 } 76 82 ?> 77 83 -
trunk/src/wp-admin/user-new.php
r38723 r38961 88 88 do_action( 'invite_user', $user_id, $role, $newuser_key ); 89 89 90 $switched_locale = switch_to_locale( get_user_locale( $user_details ) ); 91 90 92 /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */ 91 93 $message = __( 'Hi, … … 97 99 %4$s' ); 98 100 wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), sprintf( $message, get_option( 'blogname' ), home_url(), wp_specialchars_decode( translate_user_role( $role['name'] ) ), home_url( "/newbloguser/$newuser_key/" ) ) ); 101 102 if ( $switched_locale ) { 103 restore_previous_locale(); 104 } 105 99 106 $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' ); 100 107 } -
trunk/src/wp-includes/default-filters.php
r38925 r38961 407 407 add_action( 'before_delete_post', '_reset_front_page_settings_for_post' ); 408 408 add_action( 'wp_trash_post', '_reset_front_page_settings_for_post' ); 409 add_action( 'change_locale', 'create_initial_post_types' ); 409 410 410 411 // Post Formats … … 432 433 // Taxonomy 433 434 add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority 435 add_action( 'change_locale', 'create_initial_taxonomies' ); 434 436 435 437 // Canonical -
trunk/src/wp-includes/l10n.php
r38955 r38961 1179 1179 return $wp_locale->is_rtl(); 1180 1180 } 1181 1182 /** 1183 * Switches the translations according to the given locale. 1184 * 1185 * @since 4.7.0 1186 * 1187 * @global WP_Locale_Switcher $wp_locale_switcher 1188 * 1189 * @param string $locale The locale. 1190 * @return bool True on success, false on failure. 1191 */ 1192 function switch_to_locale( $locale ) { 1193 /* @var WP_Locale_Switcher $wp_locale_switcher */ 1194 global $wp_locale_switcher; 1195 1196 return $wp_locale_switcher->switch_to_locale( $locale ); 1197 } 1198 1199 /** 1200 * Restores the translations according to the previous locale. 1201 * 1202 * @since 4.7.0 1203 * 1204 * @global WP_Locale_Switcher $wp_locale_switcher 1205 * 1206 * @return string|false Locale on success, false on error. 1207 */ 1208 function restore_previous_locale() { 1209 /* @var WP_Locale_Switcher $wp_locale_switcher */ 1210 global $wp_locale_switcher; 1211 1212 return $wp_locale_switcher->restore_previous_locale(); 1213 } 1214 1215 /** 1216 * Restores the translations according to the original locale. 1217 * 1218 * @since 4.7.0 1219 * 1220 * @global WP_Locale_Switcher $wp_locale_switcher 1221 * 1222 * @return string|false Locale on success, false on error. 1223 */ 1224 function restore_current_locale() { 1225 /* @var WP_Locale_Switcher $wp_locale_switcher */ 1226 global $wp_locale_switcher; 1227 1228 return $wp_locale_switcher->restore_current_locale(); 1229 } 1230 1231 /** 1232 * Whether switch_to_locale() is in effect. 1233 * 1234 * @since 4.7.0 1235 * 1236 * @global WP_Locale_Switcher $wp_locale_switcher 1237 * 1238 * @return bool True if the locale has been switched, false otherwise. 1239 */ 1240 function is_locale_switched() { 1241 /* @var WP_Locale_Switcher $wp_locale_switcher */ 1242 global $wp_locale_switcher; 1243 1244 return $wp_locale_switcher->is_switched(); 1245 } -
trunk/src/wp-includes/load.php
r38899 r38961 842 842 * @access private 843 843 * 844 * @global string $text_direction 845 * @global WP_Locale $wp_locale The WordPress date and time locale object. 844 * @global string $text_direction 845 * @global WP_Locale $wp_locale The WordPress date and time locale object. 846 * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. 846 847 * 847 848 * @staticvar bool $loaded 848 849 */ 849 850 function wp_load_translations_early() { 850 global $text_direction, $wp_locale ;851 global $text_direction, $wp_locale, $wp_locale_switcher; 851 852 852 853 static $loaded = false; … … 865 866 require_once ABSPATH . WPINC . '/l10n.php'; 866 867 require_once ABSPATH . WPINC . '/class-wp-locale.php'; 868 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; 867 869 868 870 // General libraries … … 916 918 917 919 $wp_locale = new WP_Locale(); 920 $wp_locale_switcher = new WP_Locale_Switcher(); 921 $wp_locale_switcher->init(); 918 922 } 919 923 -
trunk/src/wp-includes/ms-functions.php
r38943 r38961 801 801 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); 802 802 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 803 804 $user = get_user_by( 'login', $user ); 805 $switched_locale = switch_to_locale( get_user_locale( $user ) ); 806 803 807 $message = sprintf( 804 808 /** … … 850 854 ); 851 855 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 856 857 if ( $switched_locale ) { 858 restore_previous_locale(); 859 } 860 852 861 return true; 853 862 } … … 887 896 if ( ! apply_filters( 'wpmu_signup_user_notification', $user, $user_email, $key, $meta ) ) 888 897 return false; 898 899 $user = get_user_by( 'login', $user ); 900 $switched_locale = switch_to_locale( get_user_locale( $user ) ); 889 901 890 902 // Send email with activation link. … … 935 947 ); 936 948 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 949 950 if ( $switched_locale ) { 951 restore_previous_locale(); 952 } 953 937 954 return true; 938 955 } … … 1449 1466 return false; 1450 1467 1468 $user = get_userdata( $user_id ); 1469 1470 $switched_locale = switch_to_locale( get_user_locale( $user ) ); 1471 1451 1472 $welcome_email = get_site_option( 'welcome_email' ); 1452 1473 if ( $welcome_email == false ) { … … 1469 1490 1470 1491 $url = get_blogaddress_by_id($blog_id); 1471 $user = get_userdata( $user_id );1472 1492 1473 1493 $welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email ); … … 1513 1533 $subject = apply_filters( 'update_welcome_subject', sprintf( __( 'New %1$s Site: %2$s' ), $current_network->site_name, wp_unslash( $title ) ) ); 1514 1534 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 1535 1536 if ( $switched_locale ) { 1537 restore_previous_locale(); 1538 } 1539 1515 1540 return true; 1516 1541 } … … 1551 1576 1552 1577 $user = get_userdata( $user_id ); 1578 1579 $switched_locale = switch_to_locale( get_user_locale( $user ) ); 1553 1580 1554 1581 /** … … 1591 1618 $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_network->site_name, $user->user_login) ); 1592 1619 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 1620 1621 if ( $switched_locale ) { 1622 restore_previous_locale(); 1623 } 1624 1593 1625 return true; 1594 1626 } -
trunk/src/wp-includes/pluggable.php
r38470 r38961 212 212 if ( ! ( $phpmailer instanceof PHPMailer ) ) { 213 213 require_once ABSPATH . WPINC . '/class-phpmailer.php'; 214 require_once ABSPATH . WPINC . '/class-smtp.php'; 214 require_once ABSPATH . WPINC . '/class-smtp.php'; 215 215 $phpmailer = new PHPMailer( true ); 216 216 } … … 1418 1418 $emails = array_flip( $emails ); 1419 1419 } 1420 1421 $switched_locale = switch_to_locale( get_locale() ); 1420 1422 1421 1423 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); … … 1523 1525 } 1524 1526 1527 if ( $switched_locale ) { 1528 restore_previous_locale(); 1529 } 1530 1525 1531 return true; 1526 1532 } … … 1569 1575 $emails[] = $user->user_email; 1570 1576 } 1577 1578 $switched_locale = switch_to_locale( get_locale() ); 1571 1579 1572 1580 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); … … 1665 1673 } 1666 1674 1675 if ( $switched_locale ) { 1676 restore_previous_locale(); 1677 } 1678 1667 1679 return true; 1668 1680 } … … 1724 1736 1725 1737 if ( 'user' !== $notify ) { 1738 $switched_locale = switch_to_locale( get_locale() ); 1726 1739 $message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n"; 1727 1740 $message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n"; … … 1729 1742 1730 1743 @wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New User Registration' ), $blogname ), $message ); 1744 1745 if ( $switched_locale ) { 1746 restore_previous_locale(); 1747 } 1731 1748 } 1732 1749 … … 1749 1766 $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) ); 1750 1767 1768 $switched_locale = switch_to_locale( get_user_locale( $user ) ); 1769 1751 1770 $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n"; 1752 1771 $message .= __('To set your password, visit the following address:') . "\r\n\r\n"; … … 1756 1775 1757 1776 wp_mail($user->user_email, sprintf(__('[%s] Your username and password info'), $blogname), $message); 1777 1778 if ( $switched_locale ) { 1779 restore_previous_locale(); 1780 } 1758 1781 } 1759 1782 endif; -
trunk/src/wp-includes/pomo/mo.php
r35714 r38961 17 17 18 18 /** 19 * Loaded MO file. 20 * 21 * @var string 22 */ 23 private $filename = ''; 24 25 /** 26 * Returns the loaded MO file. 27 * 28 * @return string The loaded MO file. 29 */ 30 public function get_filename() { 31 return $this->filename; 32 } 33 34 /** 19 35 * Fills up with the entries from MO file $filename 20 36 * … … 22 38 */ 23 39 function import_from_file($filename) { 24 $reader = new POMO_FileReader($filename); 25 if (!$reader->is_resource()) 26 return false; 27 return $this->import_from_reader($reader); 40 $reader = new POMO_FileReader( $filename ); 41 42 if ( ! $reader->is_resource() ) { 43 return false; 44 } 45 46 $this->filename = (string) $filename; 47 48 return $this->import_from_reader( $reader ); 28 49 } 29 50 -
trunk/src/wp-includes/user.php
r38905 r38961 1802 1802 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1803 1803 1804 $switched_locale = false; 1805 if ( ! empty( $send_password_change_email ) || ! empty( $send_email_change_email ) ) { 1806 $switched_locale = switch_to_locale( get_user_locale( $user_id ) ); 1807 } 1808 1804 1809 if ( ! empty( $send_password_change_email ) ) { 1805 1806 1810 /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ 1807 1811 $pass_change_text = __( 'Hi ###USERNAME###, … … 1911 1915 wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] ); 1912 1916 } 1917 1918 if ( $switched_locale ) { 1919 restore_previous_locale(); 1920 } 1913 1921 } 1914 1922 -
trunk/src/wp-settings.php
r38928 r38961 131 131 require_once( ABSPATH . WPINC . '/l10n.php' ); 132 132 require_once( ABSPATH . WPINC . '/class-wp-locale.php' ); 133 require_once( ABSPATH . WPINC . '/class-wp-locale-switcher.php' ); 133 134 134 135 // Run the installer if WordPress is not installed. … … 401 402 $GLOBALS['wp_locale'] = new WP_Locale(); 402 403 404 /** 405 * WordPress Locale Switcher object for switching locales. 406 * 407 * @since 4.7.0 408 * 409 * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. 410 */ 411 $GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher(); 412 $GLOBALS['wp_locale_switcher']->init(); 413 403 414 // Load the functions for the active theme, for both parent and child theme if applicable. 404 415 if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) { -
trunk/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
r37855 r38961 10 10 private $theme_root; 11 11 12 function setUp() {12 public function setUp() { 13 13 parent::setUp(); 14 14 … … 23 23 wp_clean_themes_cache(); 24 24 unset( $GLOBALS['wp_themes'] ); 25 25 unset( $GLOBALS['l10n'] ); 26 26 unset( $GLOBALS['l10n_unloaded'] ); 27 27 } 28 28 29 function tearDown() {29 public function tearDown() { 30 30 $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; 31 31 remove_filter( 'theme_root', array( $this, 'filter_theme_root' ) ); … … 34 34 wp_clean_themes_cache(); 35 35 unset( $GLOBALS['wp_themes'] ); 36 unset( $GLOBALS['l10n'] ); 37 unset( $GLOBALS['l10n_unloaded'] ); 36 38 37 39 parent::tearDown(); … … 61 63 $is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-plugin' ); 62 64 63 unload_textdomain( 'internationalized-plugin' );64 65 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 65 66 … … 83 84 $is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-theme' ); 84 85 85 unload_textdomain( 'internationalized-theme' );86 86 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 87 87 … … 142 142 $this->assertTrue( $is_textdomain_loaded_final ); 143 143 } 144 145 /** 146 * @ticket 26511 147 */ 148 public function test_plugin_translation_after_switching_locale() { 149 require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php'; 150 151 switch_to_locale( 'de_DE' ); 152 $expected = i18n_plugin_test(); 153 restore_previous_locale(); 154 155 $this->assertSame( 'Das ist ein Dummy Plugin', $expected ); 156 } 157 158 /** 159 * @ticket 26511 160 */ 161 public function test_theme_translation_after_switching_locale() { 162 switch_theme( 'internationalized-theme' ); 163 164 require_once get_stylesheet_directory() . '/functions.php'; 165 166 switch_to_locale( 'de_DE' ); 167 $expected = i18n_theme_test(); 168 restore_previous_locale(); 169 170 switch_theme( WP_DEFAULT_THEME ); 171 172 $this->assertSame( 'Das ist ein Dummy Theme', $expected ); 173 } 144 174 } -
trunk/tests/phpunit/tests/locale.php
r36292 r38961 2 2 3 3 /** 4 * @group l ocale4 * @group l10n 5 5 * @group i18n 6 6 */
Note: See TracChangeset
for help on using the changeset viewer.