Skip to content

Commit 5063b8d

Browse files
committed
i18n: Ensure empty strings are consistently translated to ''.
This changeset fixes an edge case where empty strings were wrongly translated to `'0'` (falsey value) instead of `''` (empty string). Props Chouby, manooweb, rafiahmedd, lopo. Fixes #55941. git-svn-id: https://develop.svn.wordpress.org/trunk@54315 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3981df5 commit 5063b8d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/wp-includes/pomo/entry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public function Translation_Entry( $args = array() ) {
8787
/**
8888
* Generates a unique key for this entry.
8989
*
90-
* @return string|false The key or false if the entry is empty.
90+
* @return string|false The key or false if the entry is null.
9191
*/
9292
public function key() {
93-
if ( null === $this->singular || '' === $this->singular ) {
93+
if ( null === $this->singular ) {
9494
return false;
9595
}
9696

tests/phpunit/tests/pomo/translations.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,31 @@ public function test_digit_and_merge() {
127127
$this->assertSame( '1', $domain->translate( '1' ) );
128128
}
129129

130+
/**
131+
* @ticket 55941
132+
*/
133+
public function test_translate_falsy_key() {
134+
$entry_empty = new Translation_Entry(
135+
array(
136+
'singular' => '',
137+
'translations' => array(
138+
'',
139+
),
140+
)
141+
);
142+
$entry_zero = new Translation_Entry(
143+
array(
144+
'singular' => '0',
145+
'translations' => array(
146+
'0',
147+
),
148+
)
149+
);
150+
$po = new Translations();
151+
$po->add_entry( $entry_empty );
152+
$po->add_entry( $entry_zero );
153+
154+
$this->assertSame( '', $po->translate( '' ) );
155+
$this->assertSame( '0', $po->translate( '0' ) );
156+
}
130157
}

0 commit comments

Comments
 (0)