I am using PHP, Zend Framework and Zend_Translate (gettext adapter). To edit translations I use POEdit which utilizes xgettext to fetch strings to be translated.
POEdit (xgettext) will search for keywords to find strings to translate. So, if searching for the keyword translate
, POEdit will have no problem finding the 'Text to translate'
string when the text is passed to the translate function directly like:
echo translate('Text to translate');
But, in ofther cases strings will be passed to Zend functions that will do the translation for me, calling the translate function with a variable as a parameter:
function SomeZendFunction( $array ) {
return translate( $array['string'] );
}
...
echo SomeZendFunction( array('string'=>'Another text to translate') );
// translate('Another text to translate');
This will cause POEdit (xgettext) to fail finding the string to translate. In the above example the string I wanted POEdit to find is 'Another text to translate'
, but since it is not passed directly to the translate
function, it will not be found.
So, how to solve the problem?
My current solution is to create a dummy file containing a long list of all the strings that was not found by POEdit:
<?php // Dummy file, only accessed by POEdit when scanning for strings to translate
translate('Text to translate');
translate('Another text to translate');
translate('A third text to translate');
....
But the downside of this solution is that when updating a string, I both need to change the dummy file and find the original string. This will make it more hard to maintain.
Another solution I thought of was adding the translation string to a comment after calling SomeZendFunction
(See the above example), but I fail to make xgettext accept it as it ignores comments.
So, anyone knows how to make xgettext to accept strings within comments? Or anyone has any other solution that might be better?
Thanks for any help!
Edit:
I don't know for what reason I was down voted. But I've tried to clarify the question.