Insert translator notes and comments in PHP files

I am working on translating the application that I am developing. I have lines like:

echo _("Welcome to my site"); 

Then I can use the command line to create the .po file from all the PHP files in a specific directory:

 find . -iname "*.php" | xargs xgettext 

However, when I import this into Poedit, I see the "Notes for translators" field. This can be useful at times, however, I cannot figure out how to fill it out. What code do I need to add to my PHP file so that xgettext adds notes for translators?

+4
source share
2 answers

Xgettext help shows:

-cTAG, --add-comments = TAG place comment blocks starting with TAG and the previous keyword lines in the output file -c, --add-comments place all comment blocks previous to the keyword lines in the output file

so add an example to your file:

// COMMENTTAG: This is another block comment that will be extracted from xgettext.

And run xgettext with -add-comments = COMMENTTAG

+6
source

In Poedit, you can go to the "File / Preferences / Extractors" menu, select the appropriate language that you extract (PHP in your case), and then click "Change." Here you can see the command used to extract translations:

xgettext --language=PHP --add-comments=TRANSLATORS: --add-comments=translators: --force-po -o %o %C %K %F

You can see and change here how additional translator comments are understood. You can use // TRANSLATORS: your notes or // TRANSLATORS: your notes in a string before using _('your text') to add these comments to the code. Example:

 // translators: 'practice' is a verb, used on a button as an action. echo _('practice'); 

Only one parameter --add-comments will be active at a time, so // translators: set as the default value in Poedit.

+2
source

Source: https://habr.com/ru/post/1480313/


All Articles