Make WordPress Core

Opened 5 months ago

Closed 2 months ago

Last modified 2 months ago

#64986 closed defect (bug) (fixed)

preview needs gettext

Reported by: timse201 Owned by: audrasjb
Priority: normal Milestone: 7.0
Component: I18N Version: 7.0
Severity: normal Keywords: has-patch
Cc: Focuses: accessibility

Description

Attachments (1)

64986.diff (2.5 KB ) - added by motylanogha 4 months 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 (29)

#1 @audrasjb
5 months ago

  • Keywords needs-patch good-first-bug added
  • Milestone Awaiting Review7.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.


5 months 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.


5 months 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:


5 months 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.


5 months ago

@motylanogha
4 months 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.


4 months ago

#7 @audrasjb
4 months 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.


3 months 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
3 months 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:


3 months 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
3 months ago

Add suggestions to the pr to simplify the context.

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


3 months ago
#12

Adds translator context to all in-tree occurrences of the 'Preview' string using a simplified _x( 'Preview', 'noun' ) or _x( 'Preview', 'verb' ), so translators can correctly disambiguate it across languages (e.g. German) where the noun and verb forms differ.

  • Buttons and action links use 'verb'.
  • Preview pane labels, table row headers, and the iframe title use 'noun'.

@wildworks commented on PR #11787:


3 months ago
#13

Closing this as a duplicate of #11700

#14 @audrasjb
3 months ago

  • Owner set to audrasjb
  • Resolutionfixed
  • Status newclosed

In 62353:

I18N: Add translator context to disambiguate translation strings for "Preview".

This changeset disambiguates translation strings for "Preview" by adding a verb|noun context to its occurrences.

Props timse201, audrasjb, anupkankale, mohamedahamed, rafaeldella, motylanogha, wildworks, jorbin, khokansardar, sergeybiryukov.
Fixes #64986.

#15 @audrasjb
3 months ago

  • Keywords dev-feedback fixed-major i18n-change added; changes-requested removed
  • Resolution fixed
  • Status closedreopened

Reopening for second committer sign-off and backport to branch 7.0.

#16 @wildworks
3 months ago

  • Keywords dev-reviewed added; dev-feedback removed

This is the second committer sign-off for [62353].

#17 @audrasjb
3 months ago

  • Resolutionfixed
  • Status reopenedclosed

In 62355:

I18N: Add translator context to disambiguate translation strings for "Preview".

This changeset disambiguates translation strings for "Preview" by adding a verb|noun context to its occurrences.

Reviewed by audrasjb, wildworks.
Merges [62353] to the 7.0 branch.
Props timse201, audrasjb, anupkankale, mohamedahamed, rafaeldella, motylanogha, wildworks, jorbin, khokansardar, sergeybiryukov.
Fixes #64986.

#18 @timse201
3 months ago

  • Resolution fixed
  • Status closedreopened

Thanks for your work.
But the initial ticket was about preview "%s". We need a fix for this, too.

#19 @audrasjb
3 months ago

  • Keywords needs-patch added; good-first-bug has-patch fixed-major i18n-change dev-reviewed removed
  • Milestone 7.07.0.1

We're a bit too close from RC4.
Let's delay this change to 7.0.1, unless a patch is provided in the next few hours we have before RC4. In that case, feel free to replace it to milestone 7.0 and we should be able to commit it.

#20 @audrasjb
3 months ago

Removing trunk version as this is not going to be shipped with WP 7.0 but in the next releases.

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


3 months ago
#21

  • Keywords has-patch added; needs-patch removed

### Description
This PR addresses Trac ticket #64986 by updating the Youtube_by_mid() function in wp-includes/meta.php to return null instead of false when validation fails or a metadata row is not found.

Currently, the function's DocBlock documentation specifies @return stdClass|null, but the actual implementation incorrectly returns false in early return statements and when the database query comes up empty. This change ensures that the function's behavior perfectly aligns with its documented return type and matches expected core standard behavior.

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

### Use of AI Tools
AI assistance: No

@wildworks commented on PR #11919:


2 months ago
#22

Hi @arifrahmanbb, this PR seems completely unrelated to Track ticket 64986. Could you clarify which ticket you are actually working on?

#24 @timse201
2 months ago

The first one is a heading (noun) and the second one an area label (verb). Comments do not separate the strings.

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


2 months ago
#25

@timse201 commented on PR #12114:


2 months ago
#26

You're right. It seems I was confused with a different string. Both strings are now fixed in de_de.
Thank you.

#27 @wildworks
2 months ago

  • Resolutionfixed
  • Status reopenedclosed

I don't think there's anything else to address in this ticket, so I'm going to close it.

#28 @sabernhardt
2 months ago

  • Milestone 7.0.17.0

([62355] was committed for inclusion in 7.0.)

Note: See TracTickets for help on using tickets.