Shot (Piotr Szotkowski) wrote:
> You need to tell Ruby you???re talking in UTF-8 to it in the first place.
> I have -Ku in my $RUBYOPT environmental variable (you can also simply
> $KCODE = 'u'
> in your Ruby code) and I get the below:

Sad to say but this is a problem that we have spent many hours trying to 
fix. By all means, try fiddling with the the KCODE variables. You may 
also want to experiment with setting the environment LANG and LC 
variables, and importing parts of irb. Good luck with that.

When that doesn't work you have two (maybe three) options.

First you can install Ruby-GNOME2, which has the function 
GLib.convert/3. That works properly on our system even though Iconv 
doesn't:

  require 'gtk2'
  GLib.convert("??????????ó??źż", "ASCII//translit", "UTF-8")

Second, you can call out to iconv through the shell:

  %x{echo '??????????ó??źż' | iconv -t ASCII//TRANSLIT}

though in that case you will have to deal with error messages and 
whatnot, which can be a bit of a pain.

The third option is write your own wrapper for libiconv. This is what 
are probably going to end up doing just to remove the RG2 dependency.

If anyone can come up with any better solutions, believe me I'm all 
ears.

Specifically, the script:

$KCODE='u'
require 'iconv'
p Iconv.iconv('ASCII//TRANSLIT', 'UTF-8', '??????????ó??źż')

when run with options:

ruby -Ku iconv.rb

produces:

["?????????"]

Whereas in irb:

$ irb
irb(main):001:0> require 'iconv'
=> false
irb(main):002:0> Iconv.iconv 'ASCII//TRANSLIT', 'UTF-8', '??????????ó??źż'
=> ["acelnoszz"]

Any Ruby gurus out there who have any idea why this should be?

Dan
-- 
Posted via http://www.ruby-forum.com/.