Make WordPress Core

Opened 6 weeks ago

Last modified 2 days ago

#64986 new defect (bug)

preview needs gettext

Reported by: timse201's profile timse201 Owned by:
Milestone: 7.0 Priority: normal
Severity: normal Version: trunk
Component: I18N Keywords: good-first-bug has-patch changes-requested
Focuses: accessibility Cc:

Attachments (1)

64986.diff (2.5 KB) - added by motylanogha 5 weeks ago.
Refreshed patch for current trunk. Adds translator context to all 4 instances of ( 'Preview' ) using _x() with descriptive context strings.

Download all attachments as: .zip

Change History (12)

#1 @audrasjb
6 weeks ago

  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to 7.0

To be clear, what is needed here is a context for translators, using the _x() function.
See https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#disambiguation-by-context

This ticket was mentioned in PR #11407 on WordPress/wordpress-develop by @anupkankale.


6 weeks ago
#2

  • Keywords has-patch added; needs-patch removed

Adds context for translators to disambiguate 'Preview' as a verb (action button) rather than a noun.

Fixes #64986

Trac ticket:

## Use of AI Tools

This ticket was mentioned in PR #11408 on WordPress/wordpress-develop by @mohamedahamed.


6 weeks ago
#3

## Summary
Fixes the ambiguous translation of the string 'Preview' used in multiple contexts. In some languages (e.g., German), different forms may be needed depending on whether 'Preview' is used as a button label, an action link, or an editor control. Without translator context, GlotPress cannot distinguish between these uses, leading to potential mistranslations.

Replaces all __( 'Preview' ) occurrences with _x( 'Preview', 'context' ) to provide explicit context for translators, consistent with the existing pattern used for other disambiguated strings in the codebase.

## Changes
src/wp-includes/class-wp-editor.php — Use _x() with 'editor button' context for the TinyMCE Preview button.
src/wp-admin/includes/class-wp-theme-install-list-table.php — Use _x() with 'theme preview action' context for the theme preview link in the install themes list table.
src/wp-admin/includes/class-wp-posts-list-table.php — Use _x() with 'post preview action' context for the preview action link in the posts list table.
src/wp-admin/includes/meta-boxes.php — Use _x() with 'button' context for the preview button text in the post submit meta box.

## Testing

  • Verify that the posts list table (/wp-admin/edit.php) still shows "Preview" action links correctly.
  • Verify that the themes install screen (/wp-admin/theme-install.php) still shows "Preview" links correctly.
  • Verify that the post edit screen preview button renders correctly.
  • Verify that the TinyMCE editor preview button is still accessible and functional.
  • Optionally: confirm the new context appears in GlotPress under the wp/dev project strings for 'Preview'.

---

Trac ticket: https://core.trac.wordpress.org/ticket/64986

---

## Use of AI Tools
AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): Claude Haiku 4.5
Used for: Identifying all affected locations and implementing the _x() replacements; changes were reviewed before submission.

@anupkankale commented on PR #11407:


6 weeks ago
#4

Trac ticket: https://core.trac.wordpress.org/ticket/64986

## Description
Adds context for translators to disambiguate 'Preview' as a verb (action button) rather than a noun.

This helps translators in languages like German where the translation differs based on whether "Preview" is used as a noun or verb.

## Changes

  • Changed __( 'Preview' ) to _x( 'Preview', 'verb, action button to preview the post' ) in src/wp-admin/includes/meta-boxes.php

## Testing

  1. The string will now appear with context in translate.wordpress.org
  2. No functional changes to the button behavior

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


6 weeks ago

@motylanogha
5 weeks ago

Refreshed patch for current trunk. Adds translator context to all 4 instances of ( 'Preview' ) using _x() with descriptive context strings.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


11 days ago

#7 @audrasjb
11 days ago

  • Keywords changes-requested added

As per today's bug scrub.
Thanks for the patch.
However I think the initial request was only to distinguish verbs from nouns. We could avoid having 4 different strings by just having _x( 'Preview', 'noun' ) and _x( 'Preview', 'verb' ).

At the very least, I think we could have the same string (button context, or even better verb) for both src/wp-admin/includes/meta-boxes.php and wp-includes/class-wp-editor.php.

This ticket was mentioned in PR #11700 on WordPress/wordpress-develop by @motylanogha.


6 days ago
#8

Preview is a single English token that lands in translations as a verb (button labels), a noun (preview panes, table headers), or an iframe title. Without translator context, all 14 in-tree occurrences collapsed onto one entry in default.po, forcing translators to choose a single rendering that fit poorly somewhere.

This PR gives each occurrence a context that names both the part of speech and the surface it appears on:

  • Post row action and post-lock dialog button (verb, ...)
  • Submit meta box preview button (verb, action button to preview the post)
  • Theme install list-table action and theme-install template buttons (verb, ...)
  • Theme preview iframe title (noun, ...)
  • Customizer toggle and takeover dialog (verb/noun, ...)
  • Header image and background image preview rows (noun, ...)
  • Classic-editor (TinyMCE) toolbar button (verb, ...)

Extends the scope of GH-11407 and GH-11408, which only covered four of these spots and used less specific context strings.

#9 @rafaeldella
6 days ago

I tested PR #11700 in my local environment (WordPress 7.0-alpha/trunk via wp-env).

I've verified the changes in the source code (e.g., in the post list table) and confirmed that the _x() function is now correctly implementing context for the "Preview" strings. I also navigated through the dashboard (Posts, Editor, and Themes) and everything is working perfectly. No regressions were found.

My environment:

  • OS: Windows 10 (WSL2)
  • Browser: Chrome
  • Setup: Docker / wp-en

@SergeyBiryukov commented on PR #11700:


6 days ago
#10

Thanks for the PR! There might be some confusion here, we don't really need a separate context for each of these strings, that would be redundant and increase the workload for translators.

As noted on the ticket already, just _x( 'Preview', 'noun' ) or _x( 'Preview', 'verb' ) would be enough here.

#11 @jorbin
2 days ago

Add suggestions to the pr to simplify the context.

Note: See TracTickets for help on using tickets.