4

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?

Mike
  • 23,542
  • 14
  • 76
  • 87

2 Answers2

6

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

Bass Jobsen
  • 48,736
  • 16
  • 143
  • 224
  • Works great. I don't suppose there is a way to not start the actual outputted comment with `TAG` is there? I didn't see that in the documentation anywhere. – Mike May 15 '13 at 09:35
  • You could use --add-comments without a tag, see also http://stackoverflow.com/questions/7665274/gettext-automatic-comments-generation – Bass Jobsen May 15 '13 at 09:54
  • Yeah, I thought of that too, but I'm not sure if somewhere in my code I have some sort of other unrelated comment that I wouldn't want showing up. – Mike May 15 '13 at 10:18
  • only comment blocks preceding keyword lines are used – Bass Jobsen May 15 '13 at 10:26
3

In Poedit, you can go to File/Preferences/Extractors menu, select the appropiate language you are extracting (PHP in your case), and then click Edit. 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 modify here how additional translator comments are parsed. You can use // TRANSLATORS: your notes or // translators: your notes in the line before you use the _('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 --add-comments parameter will be active at a time, so // translators: is set as the default in Poedit.

Roel Vermeulen
  • 594
  • 7
  • 15