Search code examples
phplocalizationgettextpoeditxgettext

Inserting translator notes/comments in PHP files


I am working on translating an application I am developing. I have strings like:

echo _("Welcome to my site");

I can then use the command line to create a .po file from all the PHP files in a particular directory by doing:

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

However, when I import this into Poedit, I see a box called "Notes for translators". This may be useful sometimes, however I can't figure out how to populate it. What code do I need to add to my PHP file so that xgettext will add notes to translators?


Solution

  • the help of xgettext shows:

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

    so add in your file by example:

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

    And run xgettext with --add-comments=COMMENTTAG