Make WordPress Core


Ignore:
Timestamp:
10/26/2016 03:35:58 PM (9 years ago)
Author:
ocean90
Message:

I18N: Introduce a locale-switching function.

With the introduction of user-specific languages in [38705] it's necessary to be able to switch translations on the fly. For example emails should be sent in the language of the recipient and not the one of the current user.

This introduces a new WP_Locale_Switcher class which is used for switching locales and translations. It holds the stack of locales whenever switch_to_locale( $locale ) is called. With restore_previous_locale() you can restore the previous locale. restore_current_locale() empties the stack and sets the locale back to the initial value.

switch_to_locale() is added to most of core's email functions, either with the value of get_locale() (site language) or get_user_locale() (user language with fallback to site language).

Props yoavf, tfrommen, swissspidy, pbearne, ocean90.
See #29783.
Fixes #26511.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/ms-delete-site.php

    r38822 r38961  
    4343    $url_delete = esc_url( admin_url( 'ms-delete-site.php?h=' . $hash ) );
    4444
     45    $switched_locale = switch_to_locale( get_locale() );
     46
    4547    /* translators: Do not translate USERNAME, URL_DELETE, SITE_NAME: those are placeholders. */
    4648    $content = __( "Howdy ###USERNAME###,
     
    7476
    7577    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    }
    7682    ?>
    7783
Note: See TracChangeset for help on using the changeset viewer.