gnue-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUe-dev] Some hints on making things translatable


From: Reinhard Mueller
Subject: [GNUe-dev] Some hints on making things translatable
Date: 21 Mar 2004 14:42:13 +0100

Hi all,

after looking through the translation stuff, I think there are some
issues I should point out.


1. _() may only contain a single fixed string.
----------------------------------------------

Wrong:
print _("This is the first line\n" + \
        "This is the second line")
Correct:
print _("This is the first line\n"
        "This is the second line")
Also correct:
print _(
"""This is the first line
This is the second line""")

Wrong:
print _("The value is '%s'" % value)
Correct:
print _("The value is '%s'") % value


2. Please use %(param)s style parameters if there are > 1 parameters
--------------------------------------------------------------------

Wrong:
print _("The value of %s is %s") % (name, value)
Correct:
print _("The value of %(name)s is %(value)s") \
      % {'name': name, 'value': value}


3. _() returns an 8-bit string, u_() returns a unicode string. Use u_()
wherever possible
-----------------------------------------------------------------------

3a. use u_() in any case when there are parameters that can be unicode
strings
----------------------------------------------------------------------

Wrong:
raise Exception, _("%s contains non-ascii characters") % myustring
Correct:
raise Exception, u_("%s contains non-ascii characters") % myustring


4. Put the _() or u_() arond the whole text, not about each line
----------------------------------------------------------------

Wrong:
tmsg = _("You can find the needed python module under ") + \
       "http://some.place/in/the/web"; + \
       _(" or in the debian package 'python-foo'")
(this will create two separate unrelated strings in the translation
file)
Correct:
tmsg = _("You can find the needed python module under "
         "http://some.place/in/the/web";
         " or in the debian package 'python-foo'")
Also Correct:
tmsg = _(
"""You can find the needed python module under
http://some.place/in/the/web
or in the debian package 'python-foo'""")
(Note that this contains newlines, while the prvious one didn't)
Also Correct:
tmsg = _("You can find the needed python module under %s "
         "or in the debian package 'python-foo'") % \
       "http://some.place/in/the/web";


I hope this is not too confusing. In case of doubt please ask :)

Thanks,
-- 
Reinhard Mueller
GNU Enterprise project
http://www.gnue.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
No army can stop an idea whose time has come.
        -- Victor Hugo, 1802-1885

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


reply via email to

[Prev in Thread] Current Thread [Next in Thread]