Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display output in original user's language #43

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
10 changes: 10 additions & 0 deletions user-switching.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,13 +934,23 @@ public static function switched_to_message( WP_User $user ) {
* @return string The message.
*/
public static function switch_back_message( WP_User $user ) {
$switched_locale = false;

if ( function_exists( 'get_user_locale' ) ) {
$switched_locale = switch_to_locale( get_user_locale( $user ) );
}

$message = sprintf(
/* Translators: 1: user display name; 2: username; */
__( 'Switch back to %1$s (%2$s)', 'user-switching' ),
$user->display_name,
$user->user_login
);

if ( $switched_locale ) {
restore_previous_locale();
}

// Removes the user login from this message without invalidating existing translations
return str_replace( sprintf(
' (%s)',
Expand Down
Loading