WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#26651 closed enhancement (fixed)

Outer spaces in wp_sprintf_l() strings are easily lost in translation

Reported by: andy Owned by: nacin
Milestone: 3.9 Priority: normal
Severity: normal Version:
Component: I18N Keywords:
Focuses: Cc:
PR Number:

Description

wp_sprintf_l() uses the following strings:

	$l = apply_filters( 'wp_sprintf_l', array(
		/* translators: used between list items, there is a space after the comma */
		'between'          => __(', '),
		/* translators: used between list items, there is a space after the and */
		'between_last_two' => __(', and '),
		/* translators: used between only two list items, there is a space after the and */
		'between_only_two' => __(' and '),
	) );

The leading and trailing spaces are frequently omitted by translators despite the translator comments.

Elsewhere, nbachiyski suggests using placeholders (%s) to assist translators.

The attached patch does just that, and then strips the placeholders before passing the array of strings through the filter.

Attachments (2)

26651.diff (1.4 KB) - added by andy 6 years ago.
Add temporary placeholders to preserve whitespace in translated strings
26651v2.diff (1.3 KB) - added by MattyRob 6 years ago.

Download all attachments as: .zip

Change History (7)

@andy
6 years ago

Add temporary placeholders to preserve whitespace in translated strings

#1 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 3.9

#2 follow-up: @MattyRob
6 years ago

Should we also perhaps consider using the _x() function rather than __() so the 'context' information is passed into the POT file?

Last edited 6 years ago by SergeyBiryukov (previous) (diff)

@MattyRob
6 years ago

#3 in reply to: ↑ 2 @SergeyBiryukov
6 years ago

Replying to MattyRob:

Should we also perhaps consider using the _x() function rather than __() so the 'context' information is passed into the POT file?

_x() is meant to distinguish the same string used in different context. A translator comment is fine here.

#4 @SergeyBiryukov
6 years ago

  • Type changed from defect (bug) to enhancement

#5 @nacin
6 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 27284:

Use placeholders in strings in wp_sprintf_l() to ensure spaces are not lost in translation.

props andy.
fixes #26651.

Note: See TracTickets for help on using tickets.