Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transliteration with Iconv in Ruby

When I'm trying to transliterate a Cyrillic utf-8 string with

Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s

(see questions/1726404/transliteration-in-ruby)

I'm getting everything but those symbols that have to be transliterated.

For example: 'r-строка' → 'r-' and 'Gévry' → 'Gvry'.

What's wrong?

Ruby 1.8.7 / Rails 2.3.5 / WSeven

like image 911
jibiel Avatar asked Dec 10 '10 15:12

jibiel


2 Answers

require 'iconv'
p Iconv.iconv('ascii//translit//ignore', 'utf-8',  'Gévry') #=> ["Gevry"]
# not         'ascii//ignore//translit'

For Cyrillic the translit gem might work.

like image 63
steenslag Avatar answered Oct 24 '22 02:10

steenslag


It seems the solution is too tricky for me. Problem solved using stringex gem.

like image 2
jibiel Avatar answered Oct 24 '22 02:10

jibiel