Some simple gettext
January 28, 2009
First, variables need to be swapped out with printf or one of its derivatives:
sprintf(_(“The value is: %s”), $value);
You can compile in comments which will show in your output file:
xgettext –add-comments=///
Static items in PHP can be problematic:
class foo {
static $bar = _(“translate”);
}
will produce a parse error. For static items, we’ve moved them below the class so they are still set upon file inclusion:
class foo {
static $bar;
}
foo::$bar = _(“translate”);
Another related problem: default method parameters will also produce a parse error.
function upgrade($upgradable = _(“default”)) { return true; }
These will also need to be moved to defaults inside the method for PHP to play nicely with gettext.