ruby, irb and iconv with translit

  • Thread starter Stefan Schmiedl
  • Start date
S

Stefan Schmiedl

Greetings.

I've been trying to find out why sorting a list of German names failed on
both my local Gentoo box and my remote Debian server. Can somebody please
explain the following in simple words?

$ ruby -v
ruby 1.8.5 (2006-12-25 patchlevel 12) [x86_64-linux]
$ irb -v
irb 0.9.5(05/04/13)


$ cat test.rb | irb5

ok, translit fails. This might be a bug somewhere,
but then why does the following work, where I called
iconv interactively, but with the same string?

$ irb -r test.rb
5=> 6


Thanks,
s.
 
S

Stefan Schmiedl

Greetings.

I've been trying to find out why sorting a list of German names failed
on both my local Gentoo box and my remote Debian server. Can somebody
please explain the following in simple words?

$ ruby -v
ruby 1.8.5 (2006-12-25 patchlevel 12) [x86_64-linux] $ irb -v
irb 0.9.5(05/04/13)


$ cat test.rb | irb5

ok, translit fails. This might be a bug somewhere, but then why does the
following work, where I called iconv interactively, but with the same
string?

$ irb -r test.rb
5=> 6

Another facet of the problem:

$ irb -r test
5
$ irb6
=> true

I'd really like to know what irb does to make iconv behave...
s.
 
S

Stefan Schmiedl

The folks at #ruby-de helped me out with some brain waves and the
problem originates with locale settings. To wit:

$ echo Ärger | LC_CTYPE=de iconv -f utf8 -t ascii//translit
?rger
$ echo Ärger | LC_CTYPE=de_DE iconv -f utf8 -t ascii//translit
AErger

But while you can get the iconv tool to behave by setting LC_CTYPE,
there's no such luck with ruby:

$ LC_CTYPE=C ruby test.rb
"?rger"
$ LC_CTYPE=de_DE ruby test.rb
"?rger"

For the record, test.rb (saved as utf8) looks like:

$KCODE='u'
require "iconv"
$conv = Iconv.new("ASCII//TRANSLIT", "UTF-8")
p($conv.iconv("Ärger"))

s.
 

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

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top