Re: [Sugar-devel] Unicode strings in translations

2012-08-16 Thread Manuel Quiñones
2012/8/16 Martin Langhoff : > As part of the gtk3 transition, we discovered importing gtk3 doesn't > have that side effect. But we want Python to assume string constants > to be UTF-8, so should tell it so explicitly instead of relying on > side-effects :-) -- look at the emails from dnarvaez and m

Re: [Sugar-devel] Unicode strings in translations

2012-08-16 Thread Martin Langhoff
On Thu, Aug 16, 2012 at 9:29 AM, Benjamin Berg wrote: > Disclaimer: I have not read the entire discussion. and you've missed a bit :-) > So, in Sugar we are mixing python unicode strings, and utf-8 encoded No. We have been _temporarily_ mixing Python unicode UTF-8 with ASCII strings. We used t

Re: [Sugar-devel] Unicode strings in translations

2012-08-16 Thread Benjamin Berg
Hello, Disclaimer: I have not read the entire discussion. So, in Sugar we are mixing python unicode strings, and utf-8 encoded python strings. This causes trouble, because once both object types are mixed, the str() object will be converted to unicode(). And this conversion fails because python u

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Martin Langhoff
On Wed, Aug 15, 2012 at 7:12 PM, Manuel Kaufmann wrote: > Take a look at this. Following what I understood from your email, if I ... We are veering far far offtopic from the subject. But string encoding is an important topic, so I'll go offtopic. > [humitos@michifus ~]$ cat test.py > #!/usr/bin/

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread S. Daniel Francis
2012/8/15 Manuel Kaufmann : > [humitos@michifus ~]$ python test.py > UTF-8, set by the first line in the script > len: 7 > last but one letter: � We agree sometimes you could need the unicode for solve some conflicts like this, but: How many translated strings are indexed by the programs? I'm real

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Manuel Kaufmann
On Wed, Aug 15, 2012 at 8:12 PM, Manuel Kaufmann wrote: > More information that you can read, pros and cons: * http://packages.python.org/kitchen/unicode-frustrations.html -- Kaufmann Manuel Blog: http://humitos.wordpress.com/ Porfolio: http://fotos.mkaufmann.com.ar/ PyAr: http://www.python.co

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Manuel Kaufmann
On Wed, Aug 15, 2012 at 10:40 AM, Martin Langhoff wrote: > len("camión") >> 7 > > CAREFUL HERE. You don't understand what is happening -- it is not as > simple as you think it is. > > When you say len("camión"), you are writing that from a terminal > (Gnome's Terminal, Sugar Terminal, xterm)

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread S. Daniel Francis
2012/8/15 Martin Langhoff : > So for example, a pure python zip compression/decompression > implementation now needs to clearly define it is _not_ working on > utf-8 streams. It started when Humitos saw the Python Unicode handling at Typing Turtle. His purpose is setup gettext for get translated d

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Martin Langhoff
On Wed, Aug 15, 2012 at 11:40 AM, S. Daniel Francis wrote: > So, the Python strings can be encoded in a Unicode compatible charset > like utf-8, the Python Unicode type is a way to encode a string if you > don't like to add a header and the recommended way to work in the > program internally, so y

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread S. Daniel Francis
2012/8/14 Gonzalo Odiard : >> - Strings with format >> Example: >> button.set_tooltip(_('Append %s') % _('something')) >> > > The problem with this example is when you have language like Spanish, > where some of the characters can be encoded in ascii, but not all. > In this case, gettext will retur

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Martin Langhoff
On Wed, Aug 15, 2012 at 9:48 AM, Daniel Narvaez wrote: > I think the reason this worked in gtk2 activities is that importing > gtk had this side effect (it's in the pango module really) > > /* set the default python encoding to utf-8 */ > PyUnicode_SetDefaultEncoding("utf-8"); Oh, can you

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Manuel Quiñones
2012/8/15 Daniel Narvaez : > I think the reason this worked in gtk2 activities is that importing > gtk had this side effect (it's in the pango module really) > > /* set the default python encoding to utf-8 */ > PyUnicode_SetDefaultEncoding("utf-8"); > > As you can see > u'¡Hola %s!' %

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Daniel Narvaez
I think the reason this worked in gtk2 activities is that importing gtk had this side effect (it's in the pango module really) /* set the default python encoding to utf-8 */ PyUnicode_SetDefaultEncoding("utf-8"); As you can see >>> u'¡Hola %s!' % 'camión' Traceback (most recent call last

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Martin Langhoff
On Wed, Aug 15, 2012 at 9:20 AM, Manuel Kaufmann wrote: > Oh, it's OK. I agree with the result. Now, let's check what Python say > if I use my default encoding (UTF8) for this simple task: > len("camión") > 7 CAREFUL HERE. You don't understand what is happening -- it is not as simple as you

Re: [Sugar-devel] Unicode strings in translations

2012-08-15 Thread Manuel Kaufmann
On Mon, Aug 13, 2012 at 2:47 PM, S. Daniel Francis wrote: > 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. Here you are another good reason to use Unicode instead any other encoding. A simple test case: How many letters has the w

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread Gonzalo Odiard
> > - Strings with format > Example: > button.set_tooltip(_('Append %s') % _('something')) > > The problem with this example is when you have language like Spanish, where some of the characters can be encoded in ascii, but not all. In this case, gettext will return a str or a PyUnicode depending of

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread S. Daniel Francis
2012/8/14 Martin Langhoff : > Perhaps you mean something else, like the "Python type Unicode". But > in general discussion, people do use Unicode to mean... Unicode ;-) Exactly, a lot of times I said unicode meaning PyUnicode, and this thread started with an issue between two different python type

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread S. Daniel Francis
2012/8/14 Manuel Kaufmann : > The reason is given here: > > "Software should only work with Unicode strings internally, converting > to a particular encoding on output." As I said, the unicode (Python type what generated this thread), is used only internally and our link gives more sense to what I

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread Manuel Kaufmann
On Tue, Aug 14, 2012 at 6:18 PM, S. Daniel Francis wrote: > Now the question is: Why should we get translations as Python type > Unicode and encode them again in utf-8? The reason is given here: "Software should only work with Unicode strings internally, converting to a particular encoding on ou

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread Martin Langhoff
On Tue, Aug 14, 2012 at 5:18 PM, S. Daniel Francis wrote: >>> strings as Unicode and encode them as utf-8? I think there are too few >>> cases when an activity gets translated strings and needs to work >>> directly with unicode. >> >> >> Probably because you do not speak chinese or any other asian

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread S. Daniel Francis
2012/8/14 Gonzalo Odiard : >> >> Unicode (Python Type) is for process text, but for input/output, that >> text will need to be encoded as a string, and for that you will need a >> code charset. Now it's the time to ask: Must we get all the translated >> strings as Unicode and encode them as utf-8?

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread Gonzalo Odiard
> > > Unicode (Python Type) is for process text, but for input/output, that > text will need to be encoded as a string, and for that you will need a > code charset. Now it's the time to ask: Must we get all the translated > strings as Unicode and encode them as utf-8? I think there are too few > ca

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread S. Daniel Francis
2012/8/14 Martin Langhoff : > Hi danielf, Hi Martin, > wrote: >> I look some people is needing to know more about Unicode: First I'll apologize because the first part of my message sounds a bit rude. > one thing to keep in mind is that UTF-8 is one of the possible ways to > represent Unicode data.

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread Manuel Kaufmann
On Tue, Aug 14, 2012 at 11:35 AM, Manuel Kaufmann wrote: > I will send a patch when I finish my work to discuss about it. http://lists.sugarlabs.org/archive/sugar-devel/2012-August/038959.html -- Kaufmann Manuel Blog: http://humitos.wordpress.com/ Porfolio: http://fotos.mkaufmann.com.ar/ PyAr:

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread Manuel Kaufmann
On Tue, Aug 14, 2012 at 10:56 AM, Martin Langhoff wrote: > The BOM header didn't become popular (for good technical reasons). Is > there a way to tell the Python interpreter that assume that our code > (inc strings in our code) should be assumed to be unicode? If so, we > can set that in sugar-ses

Re: [Sugar-devel] Unicode strings in translations

2012-08-14 Thread Martin Langhoff
On Mon, Aug 13, 2012 at 7:15 PM, S. Daniel Francis wrote: > I look some people is needing to know more about Unicode: Hi danielf, one thing to keep in mind is that UTF-8 is one of the possible ways to represent Unicode data. We will, most of the time, use UTF-8 mixed up with straight old ASCII.

Re: [Sugar-devel] Unicode strings in translations

2012-08-13 Thread Manuel Kaufmann
On Mon, Aug 13, 2012 at 6:18 PM, Gonzalo Odiard wrote: > You can read a utf8 encodec file with codecs.open too. How would you merge this with gettext? -- Kaufmann Manuel Blog: http://humitos.wordpress.com/ Porfolio: http://fotos.mkaufmann.com.ar/ PyAr: http://www.python.com.ar/

Re: [Sugar-devel] Unicode strings in translations

2012-08-13 Thread Manuel Kaufmann
On Mon, Aug 13, 2012 at 5:23 PM, Alan Jhonn Aguiar Schwyn wrote: > My solution: when load a string, convert it: > > name_converted = unicode(name, 'UTF-8') Yes, this is the __solution__. But I don't want to write this line all around my code, I expect that Python does this for me :) -- Kaufmann

Re: [Sugar-devel] Unicode strings in translations

2012-08-13 Thread Manuel Kaufmann
On Mon, Aug 13, 2012 at 5:00 PM, Martin Langhoff wrote: > I'd vote for gettext.install('po', unicode=True) everywhere. All Sugar > builds have been in the utf-8 era, so this should work even in > extremely old builds. What do you mean with "everywhere" here? Adding "gettext.install('po', unicode=

Re: [Sugar-devel] Unicode strings in translations

2012-08-13 Thread S. Daniel Francis
2012/8/13 Gonzalo Odiard : > You can read a utf8 encodec file with codecs.open too. > > http://docs.python.org/library/codecs.html > > Gonzalo I look some people is needing to know more about Unicode: The strings are encoded by default in ASCII, but with ASCII the computer can't represent all the

Re: [Sugar-devel] Unicode strings in translations

2012-08-13 Thread Gonzalo Odiard
(even the file is > UTF-8). > > My solution: when load a string, convert it: > > name_converted = unicode(name, 'UTF-8') > > > From: martin.langh...@gmail.com > > Date: Mon, 13 Aug 2012 16:00:31 -0400 > > To: humi...@gmail.com > > CC: sugar-devel@li

Re: [Sugar-devel] Unicode strings in translations

2012-08-13 Thread Alan Jhonn Aguiar Schwyn
ail.com > CC: sugar-devel@lists.sugarlabs.org > Subject: Re: [Sugar-devel] Unicode strings in translations > > On Mon, Aug 13, 2012 at 12:35 PM, Manuel Kaufmann wrote: > > To get Unicode strings from gettext I had to put these lines in my > > lesssonscreen.py file: >

Re: [Sugar-devel] Unicode strings in translations

2012-08-13 Thread Martin Langhoff
On Mon, Aug 13, 2012 at 12:35 PM, Manuel Kaufmann wrote: > To get Unicode strings from gettext I had to put these lines in my > lesssonscreen.py file: > > import gettext > gettext.install('po', unicode=True) Awright. Seems like gettext hasn't realized that it's 2012 and defaults to using codepage

Re: [Sugar-devel] Unicode strings in translations

2012-08-13 Thread S. Daniel Francis
2012/8/13 Manuel Kaufmann : > 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 Ur

[Sugar-devel] Unicode strings in translations

2012-08-13 Thread Manuel Kaufmann
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: >>> '¡Hola %s!' % 'camión' '\xc2\xa1Hola cami\xc3\xb3n!' >>> u'¡Hola %s!' % u'camión' u'\xa1Hola cami\xf3n!' >>> '¡Hola %s!' % u'