[Sugar-devel] Unicode strings in translations

S. Daniel Francis francis at sugarlabs.org
Mon Aug 13 13:47:34 EDT 2012


2012/8/13 Manuel Kaufmann <humitos at gmail.com>:
> Hello,
>
> I'm working on Typing Turtle Gtk3 port and I found an error with the
> translations encoding. The thing is we can't combine Unicode strings
> and 8-bits strings:
>
Hi, Manuel.

I'm not an expert in unicode, I learned a big part of what I know at
the PyDay Uruguay 2012, in a talk with an Argentinian speaker.

>
>>>> '¡Hola %s!' % 'camión'
> '\xc2\xa1Hola cami\xc3\xb3n!'
>

Here it's simple and easy, this is the correct usage.

> In Typing Turle the _ function (from gettext import gettext as _) is
> returning 8-bits strings, so it crashes when it tries to do something
> like this:
>
> _('Congratulations!  You earned a %(type)s medal!') % u'gold'
> [...]
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 4: ordinal not in range(128)
>

The UTF-8 encoding charset can load all the Unicode characters, and
the way to do it is adding a line at the header. The unicode type is
used for other cases.
I don't see why do you need to use unicode in this case, you could
encode all in utf-8 and forget the conflict.

> So, is there a way to make this available at Sugar level? This issue
> appears in many activities and it would be great to solve it
> "upstream" :)

I know you like upstream bugs but I think it's not necessary. If the
program will insert characters or similar actions, there is a way with
more peace, but I'm not going to explain it now if I'm not sure this
is what you need.

Cheers.
~danielf


More information about the Sugar-devel mailing list