user-switching icon indicating copy to clipboard operation
user-switching copied to clipboard

Hardcoded ASCII period after switch-back link in admin notice breaks non-English punctuation

Open hiroshisatoy opened this issue 5 months ago • 1 comments

Summary

I am a Project Translation Editor (PTE) for the Japanese translation of the User Switching plugin on WordPress.org. While reviewing the translated UI after switching users, I noticed that the admin notice reads unnaturally in Japanese—and this cannot be fixed through GlotPress alone.

After switching to another user, the admin dashboard shows a notice like:

Switched to author. Switch back to admin「.」

In Japanese, this appears as:

author に切り替えました。 admin に戻す「.」

The first sentence correctly ends with a Japanese full stop (。) from the translated string Switched to %1$s (%2$s). → %1$s (%2$s) に切り替えました。

However, an extra ASCII period (.) is appended immediately after the “Switch back” link. That trailing . is not part of the translatable string Switch back to %1$s (%2$s) (Japanese: %1$s (%2$s) に戻す). It comes from hardcoded PHP.

In Japanese typography, sentences end with 。 (U+3002 IDEOGRAPHIC FULL STOP), not . (U+002E FULL STOP). The first part of the notice correctly uses 。 via the translated string, but the hardcoded . after the switch-back link uses the wrong character for Japanese. That mismatch is what makes the notice feel unnatural, even though the link text itself is translated correctly.

As a translator, I cannot resolve this in GlotPress because the notice is built from two separate sources plus non-translatable punctuation:

Part Source Japanese (current)
First sentence Switched to %1$s (%2$s). author に切り替えました。
Link label Switch back to %1$s (%2$s) admin に戻す
Trailing . Hardcoded in PHP (not translatable) .

The same Switch back to %1$s (%2$s) string is also used elsewhere (admin bar, login screen, footer, etc.) without this trailing ., so adjusting the translation to work around the notice would break those other UI locations.

Steps to reproduce

  1. Set the site (or the originating user’s locale) to Japanese (ja).
  2. Install and activate User Switching 1.12.0 on WordPress 7.0.
  3. As an administrator, switch to another user (e.g. author).
  4. View the admin dashboard notice.

No additional plugins (e.g. WooCommerce) are required.

Actual behaviour

Immediately after switching:

The notice reads: {switched-to message}。 {switch-back link}.
An ASCII . appears directly after the link text.

On subsequent admin screens:

This notice is not limited to the page immediately after switching. On later admin screens (without the user_switched query arg), the notice still appears as only the switch-back link followed by the hardcoded . — e.g. admin に戻す. — which is especially awkward in Japanese.

Expected behaviour

In Japanese, sentence-ending punctuation should use 。, not .. Punctuation after the switch-back link should either be omitted or controlled via translatable strings so locales can use the correct character and placement (e.g. no trailing . after a link in Japanese).

Scope

This issue affects only the admin notice in action_admin_notices(). Other locations that use switch_back_message() (admin bar, login screen, footer, etc.) do not append this period.

Note: the user_switching_switched_message filter can work around this on a per-site basis, but that is not a practical fix for translators or general users.

Root cause

In user-switching.php, inside action_admin_notices(), the switch-back link is built with a non-translatable format string that includes a literal period:

$message .= sprintf(
    ' <a href="%s">%s</a>.',
    esc_url( $switch_back_url ),
    esc_html( self::switch_back_message( $old_user ) )
);

The translatable switch_back_message() string does not include this period. The official Japanese translation on WordPress.org also does not include it.

Suggested fixes

Two reasonable approaches:

Option A — Remove the hardcoded period (minimal change)

Change ' <a href="%s">%s</a>.' to ' <a href="%s">%s</a>'.

Pros: Simple, fixes the Japanese display immediately, matches other switch-back link outputs.
Cons: In English, when $just_switched is true, the notice becomes Switched to X. Switch back to Y without a final sentence-ending mark (likely still acceptable for a link at the end of a notice).

Option B — Make the wrapper string translatable (better i18n)

Replace the hardcoded format string with a translatable wrapper, for example:

/* translators: %s: Switch back link. */
$message .= ' ' . sprintf(
    __( '%s', 'user-switching' ),
    sprintf(
        '<a href="%s">%s</a>',
        esc_url( $switch_back_url ),
        esc_html( self::switch_back_message( $old_user ) )
    )
);

Or, when $just_switched is true, use a single translatable string for the full notice:

/* translators: 1: "Switched to …" message; 2: switch-back link HTML. */
__( '%1$s %2$s', 'user-switching' )

Pros: Locales can control spacing and punctuation properly.
Cons: Slightly more work; new strings would need GlotPress translations.

I would prefer Option A (remove the hardcoded .) as the smallest fix, though Option B would also work if you prefer full localisation of the notice structure.

Either option resolves the issue.

Environment

  • User Switching: 1.12.0
  • WordPress: 7.0
  • Locale: ja

hiroshisatoy avatar Jun 21 '26 02:06 hiroshisatoy

Thanks for the report @hiroshisatoy! I will remove the hardcoded period.

johnbillion avatar Jun 22 '26 09:06 johnbillion