Re: [poedit-users] not able to retrieve inside heredoc gettext in php

Olle Jonsson <[email protected]> Mon, 23 Jun 2008 11:08:20 +0200
Newsgroups gmane.editors.poedit.user
Message-ID <[email protected]>
On 19 jun 2008, at 17.06, Ricard Coll wrote:

I know may be it is not the most elegant way, but it uses heredoc (END_OF_TEXT in the example below):

Hi Mr Coll (and other PHP-using lurkers),

For some reason, we defined a t_() function, that we only ever called with double quotes, so xgettext could pick it up.:

echo sprintf( t_("Welcome, %s"), $firstname );

A sample xgettext invocation.

tree -fi | \
grep -v 'Test.php$'| \
grep "\.php$" | \
xgettext --keyword=t_ \
--from-code=iso-8859-1 \
--foreign-user \
-o tmp_php_messages.pot \
-f -

1. tree -fi is a useful ls alternative, requiring no awk or the like. There's more than one way to do it, of course.
2. We exclude the PHPUnit test files (our test cases sit next to the file they test).
3. Include the regular PHP files.
4. Invoke xgettext saying the -f ("file") is standard input. The "keyword" indicates our t_() function. The PHP we read was encoded in latin1. We output the resulting PO template file as tmp_php_messages.pot. The "foreign" in --foreign-user means "non-FSF user".

These articles helped me:

http://www.thinkvitamin.com/features/webapps/give-your-web-app-international-appeal
http://www.thinkvitamin.com/features/webapps/give-your-web-app-international-appeal-part-ii

best of luck with the i18n effort,
Olle Jonsson

PS: Also, after a short experiment, this also came to me:

<?php
// Assumption: T_ESCAPE_SINGLE being some app-specific constant
// to control some behavior in t_().
echo t_(T_ESCAPE_SINGLE, "This guy won't be picked up by xgettext.");
echo t_("Hey buster");
?>

It seems xgettext only likes the simple arg list.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

_______________________________________________
Poedit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/poedit-users