Skip to content

Instantly share code, notes, and snippets.

@mathie
Created October 16, 2008 12:59
Show Gist options
  • Save mathie/17126 to your computer and use it in GitHub Desktop.
Save mathie/17126 to your computer and use it in GitHub Desktop.
# Replaces accented characters with their ascii equivalents.
def transliterate(string)
Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s
end
# The iconv transliteration code doesn't function correctly
# on some platforms, but it's very fast where it does function.
if "foo" != Inflector.transliterate("föö")
def transliterate(string)
string.mb_chars.normalize(:kd). # Decompose accented characters
gsub(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics).
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment