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 -->
   <summary>Profile</summary>

Scheme (.scm) files

See this post.

Mallard documentation files

   <p xmlns:its="http://www.w3.org/2005/11/its" its:locNote="Translators: Comment about text to translate.">Text to translate</p>

TranslationProject/DevGuidelines/Use comments (last edited 2018-03-18 14:01:35 by AndreKlapper)