0

i used iconv to replace the character:

<%= Iconv.iconv("ascii//translit", "utf-8", "ENDÜœSTRIYEL").to_s %>

it displays, END?oeSTRIYEL

whereas in irb it shows like this:

irb(main):006:0> Iconv.iconv('ascii//translit', 'utf-8', 'ENDÜœSTRIYEL').to_s
=> "ENDUoeSTRIYEL"

how to get the full translation of the nonascii characters as in irb?

Thanks.

User_28
  • 55
  • 1
  • 2
  • 9

1 Answers1

0

The iconv facility of glibc has a transliteration that depends on the locale:

$ echo "ENDÜœSTRIYEL" | LC_ALL=C iconv -f utf-8 -t ascii//translit
END?oeSTRIYEL
$ echo "ENDÜœSTRIYEL" | LC_ALL=de_DE.UTF-8 iconv -f utf-8 -t ascii//translit
ENDUEoeSTRIYEL
$ echo "ENDÜœSTRIYEL" | LC_ALL=ja_JP.UTF-8 iconv -f utf-8 -t ascii//translit
ENDUoeSTRIYEL

As you can see, three different results for three different locales.

If you are hosting a server that is meant to handle input from users in different countries, you have two options:

  • Use a single locale for all users, and hope it's good enough for all.
  • Switch the locale temporarily for each conversion (using uselocale, not setlocale). However, I don't know whether uselocale is available in Ruby.
Bruno Haible
  • 1,203
  • 8
  • 8