0

i wanted to ask a question about converting string.

i am using Rails 4.0.4

And in my database i have values which are in my native language like Rīga or Jēkabpils. I was wondering if there is some kind of function or other way to convert this words to english symbols/characters like Riga or Jekabpils.

I am wondering this because i would like to do this so i could compare them

like:

"Jēkabpils".convert == "Jekabpils"

I am asking this purely based on my own interest, i am just wondering if this is even possible?

user2945241
  • 360
  • 5
  • 19
  • 3
    possible duplicate of [Ruby method to remove accents from UTF-8 international characters](http://stackoverflow.com/questions/15686752/ruby-method-to-remove-accents-from-utf-8-international-characters) – Jakub K Jun 27 '14 at 12:38
  • ok thx Jacob K. I will look in to this – user2945241 Jun 27 '14 at 13:04

1 Answers1

1

You can do it like this:

require "i18n"
I18n.enforce_available_locales = false
s = "Jēkabpils"
puts s
puts I18n.transliterate(s)

Output:

Jēkabpils
Jekabpils
John C
  • 4,276
  • 2
  • 17
  • 28
  • this more like writing every word a translations, i have like 300 cities in my database and the numbers will grow. Is there a way to do this to a character? – user2945241 Jun 27 '14 at 13:43