FAQ Index - Search - Recent Changes - Everything - Add entry

<< Previous Entry | FAQ Entry 23.30 | Next Entry >>

23.30. Q_() is not available in my pygtk app. How to use Qualified translatable strings?

glib 's gstrfuncs.c

has:

 G_CONST_RETURN gchar *
 g_strip_context  (const gchar *msgid, 
		  const gchar *msgval)
 {
  if (msgval == msgid)
    {
      const char *c = strchr (msgid, '|');
      if (c != NULL)
	return c + 1;
    }

  return msgval;
 }
which is defined as #define Q_(String) g_strip_context ((String), gettext (String))

now this is done in python this way (apart from the | check which I did not implement):

 def Q_(s):
   s = _(s)
   if s[0] == '?':
       s = s[s.find(':')+1:] # remove ?abc: part
   return s
Now some theory..

in your code you do:

 menu.name = Q_('?vcard:Unknown')
 special.name = Q_('?os:Unknown') 
so pot will have:

 #: vcard.py:123 
 msgid "?vcard:Unknown" 
 msgstr "" 

 #: vcard.py:126
 msgid "?os:Unknown" 
 msgstr ""
translators get the idea how to translate Unknown and then can either do their translation either by including the ?zzz: part or without

this helps them so then now the context but moreover the know that gender (masculine, feminine, neutral)

thanks to piman, nkour

PyGTK FAQ Wizard | PyGTK Homepage | Feedback to faq at pygtk.org