[Kde-bindings] Text encoding in Ruby 1.8 plugins

David Palacio dpalacio at orbitalibre.org
Tue Feb 15 19:25:57 UTC 2011


Hi,

When passing UTF8 text to Qt widgets the text appears garbled. Setting
$KCODE='u' in the plugin code does not fix it as QtRuby might have
already guessed how to encode Ruby strings (see init_codec() in
handlers.cpp). And the interpreter sets $KCODE to "NONE" by default,
so ruby strings are always treated as Latin strings. I am thinking of
two solutions for this:

1. Use to/fromLocal8Bit as default case when converting strings.
2. Let krubypluginfactory set $KCODE when -Kkcode is set in RUBYOPT
environment variable.

I prefer 1. as my current problem does not involve utf8 strings in the
code at all, but only user data (from a 3rd party library), that might
be in any encoding, in any locale. fromLocal8Bit should handle this well. 
What I do not like about 2. is that it requires each user to modify
their environment.

What do you think? Am I missing a way to set $KCODE early?

Regards,

David




More information about the Kde-bindings mailing list