[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
xgettext: problems with PHP heredocs
From: |
Gaëtan Frenoy |
Subject: |
xgettext: problems with PHP heredocs |
Date: |
Fri, 5 May 2006 14:56:03 +0200 |
Package: gettext-base
Version: 0.14.4-2
Hello,
Here is a patch to an bug I discovered in xgettext.
Note that this problem was already reported a while ago
in gnu.utils.bug
(see
http://groups.google.be/group/gnu.utils.bug/tree/browse_frm/thread/94bed260e
b3dde71/e8c679cb94fb3b8a)
But so far, I did not find any fix.
First let's describe the problem. Say you have the
following PHP source file.
-------- bug_heredoc.php -------------------------- start -
<?php
$foo = _("Bar");
echo <<<_END_
[...]
<script language="javascript">
[...]
</script>
_END_;
$foo2 = _("Bar2");
?>
-------- bug_heredoc.php ---------------------------- end -
Now, run "xgettext" to extract marked strings :
-- xgettext call ---------------------------------- start -
$ xgettext -L PHP --omit-header heredoc_bug.php -o -
#: heredoc_bug.php:3
msgid "Bar"
msgstr ""
-- xgettext call ------------------------------------ end -
Surprisingly, "Bar2" is not reported nor any of marked
strings located after the end of PHP heredoc section.
If you are not familiar with PHP, here are some words
about Heredoc syntax:
http://www.php.net/manual/en/language.types.string.php#language.types.string
.syntax.heredoc
I am running the software version on a Debian stable
("Sarge") system :
-- xgettext version ------------------------------ start -
$ xgettext --version
xgettext (GNU gettext-tools) 0.14.4
(...)
$ apt-cache policy gettext
gettext:
Installé : 0.14.4-2
Candidat : 0.14.4-2
Table de version :
*** 0.14.4-2 0
500 ftp://ftp.belnet.be sarge/main Packages
100 /var/lib/dpkg/status
-- xgettext version -------------------------------- end -
However, it looks like the problem is not yet fixed in
0.14.5.
By digging into the code, I found the following fix
for gettext-tools/src/x-php.c :
-- x-php.c patch --------------------------------- start -
$ diff -abu x-php.orig.c x-php.c
--- x-php.orig.c 2003-12-30 12:30:01.000000000 +0100
+++ x-php.c 2006-05-04 19:14:43.434424200 +0200
@@ -1087,12 +1087,18 @@
{
int bufidx = 0;
+ /* Skip blank lines before processing
+ * possible label */
+ do
+ c = phase1_getc ();
+ while (c != EOF && (c == '\n' || c == '\r'));
+
while (bufidx < bufpos)
{
c = phase1_getc ();
if (c == EOF)
break;
- if (c != buffer[bufidx])
+ if (c != buffer[bufidx++])
{
phase1_ungetc (c);
break;
-- x-php.c patch ----------------------------------- end -
And now xgettext behaves as expected.
Hope this helps.
--
Gaëtan Frenoy (gaetan -à- frenoy -point- net)
- xgettext: problems with PHP heredocs,
Gaëtan Frenoy <=