[wp-trac] [WordPress Trac] #55941: Empty string wrongly translated to '0'

WordPress Trac noreply at wordpress.org
Tue Jun 7 18:15:39 UTC 2022


#55941: Empty string wrongly translated to '0'
--------------------------+---------------------
 Reporter:  Chouby        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  6.1
Component:  I18N          |     Version:  2.8
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+---------------------
Description changed by sabernhardt:

Old description:

> I encountered a case where an empty string is translated to `'0'`, when I
> expected it to be `''`. This edge case is due to the translation file
> having the string `'0'`, translated to `'0'`.
>
> According to the PHP documentation
> https://www.php.net/manual/en/language.types.array.php, in array keys,
> - null is the same as ''
> - false and '0' are the same as 0
>
> In `Translation_Entry::key()` we can find:
>
> {{{#!php
> <?php
> if ( null === $this->singular || '' === $this->singular ) {
>         return false;
> }
> }}}
>
> The singular string being the key of the entries array, that means that
> `null`, `''`, `false`, `0` and `'0'` all have the same translation.
> I don't expect non-string keys to be used, but `''` and `'0'` are two
> valid strings which should accept different translations.

New description:

 I encountered a case where an empty string is translated to `'0'`, when I
 expected it to be `''`. This edge case is due to the translation file
 having the string `'0'`, translated to `'0'`.

 According to the PHP documentation
 https://www.php.net/manual/en/language.types.array.php, in array keys,
 - `null` is the same as `''`
 - `false` and `'0'` are the same as `0`

 In `Translation_Entry::key()` we can find:

 {{{#!php
 <?php
 if ( null === $this->singular || '' === $this->singular ) {
         return false;
 }
 }}}

 The singular string being the key of the entries array, that means that
 `null`, `''`, `false`, `0` and `'0'` all have the same translation.
 I don't expect non-string keys to be used, but `''` and `'0'` are two
 valid strings which should accept different translations.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55941#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list