Use comments

Gettext has a nice and very useful feature where any comments in the source code that are immediately preceding a message marked for translation, are being automatically picked up and displayed as comment in the .po file next to the message in question.

C / C++ files

Below is a code example from line 42 in a file called foo.c:

   /* This is the verb, not the noun */
   g_printf (_("Profile"));

This will automatically turn into this in the .pot and .po files:

   #. This is the verb, not the noun
   #: foo.c:42
   msgid "Profile"
   msgstr ""

Gettext will pick up multi-line comments as well.

As you can see, this feature can be very useful for providing additional and sometimes very much necessary information for translators, so that the message can be translated correctly. As gettext automatically picks up all comments that happen to be immediately preceding a message and places them next to the messages in the pot and po files this way, the comments that are actually intended for translators can be difficult to distinguish sometimes. Thus, making them explicitly address translators usually helps in catching the translators' notice:

   /* Translators: This is the verb, not the noun */
   g_printf (_("Profile"));

Glade / GTKBuilder files

To receive the same results for a Glade or GTKBuilder file, add the "comments" parameter to the markup item:

   <property name="label" translatable="yes" comments="Translators: This is the verb, not the noun">Profile</property>

Note that the order of attributes matters. translatable should come before comments.

GSettings schema files

In .gschema files, comments need to be placed before the opening tag. Example:

   <!-- Translators: This is the verb, not the noun -->

Scheme (.scm) files

See this post.

TranslationProject/DevGuidelines/Use comments (last edited 2017-05-31 01:15:07 by PiotrDrag)