php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67423 ngettext() returns po file headers when first param is an empty string
Submitted: 2014-06-11 21:16 UTC Modified: 2014-08-11 21:31 UTC
From: phil at propcom dot co dot uk Assigned:
Status: Not a bug Package: Gettext related
PHP Version: 5.4.29 OS: Centos
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
22 + 42 = ?
Subscribe to this entry?

 
 [2014-06-11 21:16 UTC] phil at propcom dot co dot uk
Description:
------------
When ngettext is called with an empty string as the first parameter, it returns the unparsed headers from the PO (or indeed MO) file.

Test script:
---------------
https://gist.github.com/phil-lavin/ac3e3c20fd0e902f6f88

Expected result:
----------------
1 Produkt
<no output>


Actual result:
--------------
As per Gist

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-11 21:31 UTC] santiagolizardo@php.net
-Status: Open +Status: Not a bug
 [2014-08-11 21:31 UTC] santiagolizardo@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Despite being a bit confusing, that's what the gettext library is supposed to be returning when you give an empty string for translation.

If you are curious about the reason, please read the MO format section of gettext from its official website:

http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files

"Having the original strings sorted enables the use of simple binary search, for when the MO file does not contain an hashing table, or for when it is not practical to use the hashing table provided in the MO file. This also has another advantage, as the empty string in a PO file GNU gettext is usually translated into some system information attached to that particular MO file, and the empty string necessarily becomes the first in both the original and translated tables, making the system information very easy to find."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC