[Sugar-devel] [PATCH sugar-toolkit-gtk3] Use class-based API for gettext translations

Manuel Kaufmann humitos at gmail.com
Tue Aug 14 19:34:20 EDT 2012


On Tue, Aug 14, 2012 at 7:35 PM, Daniel Drake <dsd at laptop.org> wrote:
> Show us an activity that fails because of this and give some
> details/explanation.

I've already explain this on the other thread (I linked it in this one
too), it talks about Typing Turtle and the "Congratulation.." string
but don't worry.

There is another activity that has this problem as well: Get Books.
This commit shows the "hack" that we have to use to combine 8bits and
Unicode strings:

 * http://git.sugarlabs.org/get-books/mainline/commit/165ce7c28a51ec016f9b4dcbb2dd27203539d186

I'm sure that is not the correct way to handle this problem and I'm
100% sure this should be solved using Unicode throughout the code but
maybe I'm wrong in the way that I'm proposing. I'm not a Sugar expert.

The REAL problem is mixing of Unicode with 8bits strings. We have to
decide to use ONLY one of them and there are many reasons for use
Unicode (as I pointed you out on the other thread). We MUSTN'T mix
them.

Some examples with weird results:

* Unicode + Unicode -> No problem

>>> u'Tengo un ' + u'camión'
u'Tengo un cami\xf3n'

* 8bits (utf8) + 8bits (utf8) -> No problem

>>> 'Tengo un ' + 'camión'
'Tengo un cami\xc3\xb3n'

* 8bits (utf8) + Unicode -> No problem

>>> 'Tengo un ' + u'camión'
u'Tengo un cami\xf3n'

* Unicode + 8bits (utf8) -> CRASH !!

>>> u'Tengo un ' + 'camión'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
4: ordinal not in range(128)

So, Unicode at the left side of the operator crash... Is that an
expected behaviour? Why it doesn't crash at the right side too? Should
I check every strings on my code? We need an unique way to handle our
strings and Unicode comes to my mind  everytime :) . Python's gettext
module and Unicode's documentation recommend that, why are we going to
go in the opposite direction?

Cheers,

-- 
Kaufmann Manuel
Blog: http://humitos.wordpress.com/
Porfolio: http://fotos.mkaufmann.com.ar/
PyAr: http://www.python.com.ar/


More information about the Sugar-devel mailing list