1
votes

I'm using poEdit with the xgettext-Parser to parse my PHP source files and detect all translatable strings. By default, xgettext only recognizes strings in function calls like translate("foo"), if "translate" is specified as a keyword for xgettext.

Now I have some translatable strings in PHP-arrays, like

array(
    'label' => 'foo',
);

or DocBlocks like

/**
 * @FormElement(type="text", options={
 *     "label"="Foobar",
 * })
 */

How can I manage to recognize these translatable strings "foo" or "Foobar" with xgettext?

Thanks in advance!

1
Did you find a solution yet?Oytun
@OytunTez See my suggestion in the answer below.Radu Maris
Thank you for the update, @RaduMaris.Oytun

1 Answers

0
votes

You could create a dummy translate method, and use that when you create your array:

function dummy_translate ($string)
{
    return $string;
}

$array = array
(
    'label' => dummy_translate('foo')
);

And extract with:

xgettext --keyword=dummy_translate:1

Also as your xgettext keywords must form a valid C identifier, you cannot do this, just before the array:

$dummy_method = function ($string)
{
    return $string;
}

Just find a good place to put your dummy method.

Did not use DocBlocks for more than documentations, so not sure about that, but I guess a similar approach should work there to.

P.S. The performance of the extra function call is negligible, please don't waste time with micro-optimizations.