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 ""

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:

   /* To 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="To 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 .schemas files, comments need to be inside <default>, <short> or <long> elements (i.e. they cannot be before the opening tag). Example

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

Scheme (scm) files

See this posting.

TranslationProject/DevGuidelines/Use comments (last edited 2011-11-25 11:53:14 by AndreKlapper)