qtruby overrides "to_s" depending on user's LOCALES

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

Hi, is it an appropiate list for asking about QtRuby?

Note the following issue:

=2D---------------------
~# export LANG=3Des_ES.UTF-8

~# irb1.8

irb> require "Qt4"=20

irb> num =3D 1.1
irb> puts num
1.1

irb> app =3D Qt::Application.new(ARGV)
#<Qt::Application:0x7f48392e6a70 objectName=3D"irb1.8">

irb> puts num
1,1
=2D---------------------

As you can see, after creating a Qt::Application instance, FixNum#to_s has=
=20
been overriden and prints the number in a format depending on user's LOCALE=
S=20
(in Spanish 1.1 is displayed as 1,1).


I've critical issues with it because I use some external libraries as=20
httpclient which creates wrong HTTP request after creating a instace of=20
Qt::Application:

GET /index.html HTTP/1,1 <--- Note 1,1 !!!


Is there any way to disable this behaviour in QtRuby? any workaround?
Thanks a lot.





=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
S

Stefano Crocco

|Hi, is it an appropiate list for asking about QtRuby?
|
|Note the following issue:
|
|----------------------
|~# export LANG=3Des_ES.UTF-8
|
|~# irb1.8
|
|irb> require "Qt4"
|
|irb> num =3D 1.1
|irb> puts num
|1.1
|
|irb> app =3D Qt::Application.new(ARGV)
|#<Qt::Application:0x7f48392e6a70 objectName=3D"irb1.8">
|
|irb> puts num
|1,1
|----------------------
|
|As you can see, after creating a Qt::Application instance, FixNum#to_s h= as
|been overriden and prints the number in a format depending on user's
| LOCALES (in Spanish 1.1 is displayed as 1,1).
|
|I've critical issues with it because I use some external libraries as
|httpclient which creates wrong HTTP request after creating a instace of
|Qt::Application:
|
| GET /index.html HTTP/1,1 <--- Note 1,1 !!!
|
|
|Is there any way to disable this behaviour in QtRuby? any workaround?
|Thanks a lot.
|

You can certainly post QtRuby related questions here, but probably you'll g=
et=20
more answers using the qtruby mailing list (e-mail address removed) or the qtru=
by=20
forum: http://rubyforge.org/forum/forum.php?forum_id=3D723.

Regarding your question, you can find an explaination of why this happens (=
and=20
some workarounds) in this thread of the qtruby forum:=20
http://rubyforge.org/forum/message.php?msg_id=3D67059

If you only want a quick solution, you can do the following: create a=20
Qt::Locale object based on the C locale using Qt::Locale.c, sets its=20
number_options property to Qt::Locale::OmitGroupSeparator and use its=20
to_string method to create the string. Something like this:

x =3D 1234.567
l =3D Qt::Locale.c
l.number_options =3D Qt::Locale::OmitGroupSeparator
puts l.to_string(x)

Without changing the number_options property, you'll get a number separator=
in=20
the string (in the example, you'd get the string "1,234.567").

I hope this helps

Stefano
 
I

Iñaki Baz Castillo

El Domingo, 2 de Agosto de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
Hi, is it an appropiate list for asking about QtRuby?

Note the following issue:

----------------------
~# export LANG=3Des_ES.UTF-8

~# irb1.8

irb> require "Qt4"

irb> num =3D 1.1
irb> puts num
1.1

irb> app =3D Qt::Application.new(ARGV)
#<Qt::Application:0x7f48392e6a70 objectName=3D"irb1.8">

irb> puts num
1,1
----------------------

As you can see, after creating a Qt::Application instance, FixNum#to_s has
been overriden and prints the number in a format depending on user's
LOCALES (in Spanish 1.1 is displayed as 1,1).


ops, a related thread with no happy final:
http://rubyforge.org/forum/forum.php?thread_id=3D32460&forum_id=3D723


=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
I

Iñaki Baz Castillo

El Domingo, 2 de Agosto de 2009, Stefano Crocco escribi=C3=B3:
Regarding your question, you can find an explaination of why this happens
(and some workarounds) in this thread of the qtruby forum:
http://rubyforge.org/forum/message.php?msg_id=3D67059

Yes, after sending the mail I found the same thread :)

If you only want a quick solution, you can do the following: create a
Qt::Locale object based on the C locale using Qt::Locale.c, sets its
number_options property to Qt::Locale::OmitGroupSeparator and use its
to_string method to create the string. Something like this:

x =3D 1234.567
l =3D Qt::Locale.c
l.number_options =3D Qt::Locale::OmitGroupSeparator
puts l.to_string(x)

But this is not valid to me since I use 3rd party libraries (as httpclient =
=20
which suffers this issue when generating a HTTP request).

Then, I assume that I must change the locales globally but this would break=
=20
the Qt translations and so... :(

Dark issue...

Thanks a lot.





=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
S

Stefano Crocco

|El Domingo, 2 de Agosto de 2009, Stefano Crocco escribi=C3=B3:
|> Regarding your question, you can find an explaination of why this
|> happens (and some workarounds) in this thread of the qtruby forum:
|> http://rubyforge.org/forum/message.php?msg_id=3D67059
|
|Yes, after sending the mail I found the same thread :)
|
|> If you only want a quick solution, you can do the following: create a
|> Qt::Locale object based on the C locale using Qt::Locale.c, sets its
|> number_options property to Qt::Locale::OmitGroupSeparator and use its
|> to_string method to create the string. Something like this:
|>
|> x =3D 1234.567
|> l =3D Qt::Locale.c
|> l.number_options =3D Qt::Locale::OmitGroupSeparator
|> puts l.to_string(x)
|
|But this is not valid to me since I use 3rd party libraries (as httpclie= nt
|which suffers this issue when generating a HTTP request).

You can try redefining the Float#to_s method after creating the application=
,=20
using the code I suggested inside it. This works in a simple example, but I=
'm=20
not sure what would happen in a real situation.

require 'Qt4'

a =3D Qt::Application.new []

class Float
def to_s
l =3D Qt::Locale.c
l.number_options =3D Qt::Locale::OmitGroupSeparator
l.to_string(self)
end
end
x =3D 1234.567
puts x

Stefano
 
I

Iñaki Baz Castillo

El Domingo, 2 de Agosto de 2009, Stefano Crocco escribi=C3=B3:
You can try redefining the Float#to_s method after creating the
application, using the code I suggested inside it. This works in a simple
example, but I'm not sure what would happen in a real situation.

require 'Qt4'

a =3D Qt::Application.new []

class Float
def to_s
l =3D Qt::Locale.c
l.number_options =3D Qt::Locale::OmitGroupSeparator
l.to_string(self)
end
end
x =3D 1234.567
puts x


Thanks, I already saw this solution in the RubyForge thread. However I'm=20
afraid of what could happen if this issue affects to more Ruby classes than=
=20
just Float. But it seems the bets solution (even if it's obviously a painfu=
l=20
hack XD).

Thanks a lot.


=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top