Possible Duplicate:
Transliteration in ruby
I am searching for a simple way to convert strings like these:
- “spaß” to “spass”
- “über” to “ueber”
- etc.
This is needed for generating valid usernames from names of people.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is called transliteration. An approximation of this (see examples) can be performed using the Iconv class.
Try one of the following (require ‘iconv’ first):
There’s also an
iconvcommand line utility. More information on that and some Ruby examples (search for ‘ruby’) here.An alternative to this is Unidecode, which I guess was inspired by the original Perl implementation. I haven’t used it in its Ruby incarnation, but it should do multi-char expansions (which apparently you want) better.
Finally, if you’re running Rails, you may find this thread interesting. It details some differences between alternative approaches to transliteration, and shows a way to do this within the Rails core (
ActiveSupport::Inflector.transliterate)