mirror of
git://develop.git.wordpress.org/
synced 2025-02-07 08:04:27 +01:00
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
This commit is contained in:
parent
3981df5b30
commit
5063b8d218
@ -87,10 +87,10 @@ if ( ! class_exists( 'Translation_Entry', false ) ) :
|
||||
/**
|
||||
* Generates a unique key for this entry.
|
||||
*
|
||||
* @return string|false The key or false if the entry is empty.
|
||||
* @return string|false The key or false if the entry is null.
|
||||
*/
|
||||
public function key() {
|
||||
if ( null === $this->singular || '' === $this->singular ) {
|
||||
if ( null === $this->singular ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -127,4 +127,31 @@ class Tests_POMO_Translations extends WP_UnitTestCase {
|
||||
$this->assertSame( '1', $domain->translate( '1' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 55941
|
||||
*/
|
||||
public function test_translate_falsy_key() {
|
||||
$entry_empty = new Translation_Entry(
|
||||
array(
|
||||
'singular' => '',
|
||||
'translations' => array(
|
||||
'',
|
||||
),
|
||||
)
|
||||
);
|
||||
$entry_zero = new Translation_Entry(
|
||||
array(
|
||||
'singular' => '0',
|
||||
'translations' => array(
|
||||
'0',
|
||||
),
|
||||
)
|
||||
);
|
||||
$po = new Translations();
|
||||
$po->add_entry( $entry_empty );
|
||||
$po->add_entry( $entry_zero );
|
||||
|
||||
$this->assertSame( '', $po->translate( '' ) );
|
||||
$this->assertSame( '0', $po->translate( '0' ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user