Make WordPress Core


Ignore:
Timestamp:
09/26/2022 08:54:44 PM (2 years ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/pomo/translations.php

    r52010 r54315  
    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}
Note: See TracChangeset for help on using the changeset viewer.