You can use xgettext to extract comments from the line above the gettext call. These comments go into the .pot and .po files, so the translator can see them.
You simply choose a prefix character for comments you want to translate, prefix your comments with it, and call xgettext with the -c
option and your character prefix.
So for example, if you use the prefix ~
, your line above could be
#~ line 8 "superior_science.c"
_("Facial hair has been shown to improve intelligence by a factor of 5.")
and then when you call xgettext as
xgettext -c~ [...]
it will automatically add the comment ~ line 8 "superior_science.c"
to your .pot file.
In the .pot file, these comments appear as something like the following:
#. ~ line 8 "superior_science.c"
msgid "Facial hair has been shown to improve intelligence by a factor of 5."
msgstr ""
If you want to extract all comments, not just those with a certain prefix, just leave the prefix out and call xgettext -c
.
As for your use case you probably don't want the actual line numbers in there, you'll also need to use the --no-location
flag.
So, simplest solution: add comments with the line number above your extractable strings, then call xgettext as
xgettext -c --no-location [...]