I just came across this post because I was also looking for a way to do this, and just wanted to add that @Paiman Roointans' solution works because PoEdit uses the TRANSLATORS:
tag as default tag for comment extraction via gettext.
This can actually be seen if you open PoEdit -> Preferences -> Extractors, then click on the little "+" button at the bottom left of the window, which will show you the command PoEdit fires by default for an extraction of your translation strings from the source file, which is sth like:
xgettext -L PHP --add-comments=TRANSLATORS: --force-po -o %o %C %K %F
where %o %C %K %F
are the respective placeholders, for example %o
for the output filename, %K
for the keyword list (you specify in POEdits keyword mask), etc.
To change the default comment identifier in PoEdit, simply go to Translation -> Properties -> Click on "Advanced Extraction Preferences" under de "Translation Properties" tab of the window which then pops up. Normally the first field there should tell you the current string being used as comment identifying tag. Change that for example to mysamplecommentkey
, and write a translation like this in your PHP
code, for example:
/* mysamplecommentkey: This is a test */
gettext( "Translate Me" );
And your "Translate Me" will have the This is a test
comment attached to it when extracting from the source code.
And, just another point: You should rather use a POT
instead of a PO
template file for your gettext localizations in PoEdit. Set all of your keyword extractors and / or comment identifier string, then extract from your source code into your .pot
file, everytime when you update your translations.
Then, in all of your PO
files, you simply hit update from POT-File
in PoEdit, and it will correctly update all of your translations, including all of the comments for translators, which will all be drawn from the POT file directly too (so you better write these translator comments in a language that all of your translators most likely understand).
It took me some time to figure all of this out, and I would have saved tons of hours if I knew all of this from upon the beginning, so I wanted to share this here. If used correctly, PoEdit (already the free version of it) can save you a lot of time!