[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [GNUe-dev] Some hints on making things translatable
From: |
Jason Cater |
Subject: |
Re: [GNUe-dev] Some hints on making things translatable |
Date: |
Sun, 21 Mar 2004 11:23:09 -0600 |
User-agent: |
KMail/1.6.1 |
Reinhard,
Since we put _() in the builtin dict ourselves, should we just make _() act
like u_() ?
Or is the pygettext package hardcoded to expect _() to be non-unicode?
-- Jason
On Sunday 21 March 2004 07:42 am, Reinhard Mueller wrote:
> 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,