class I18n::Backend::Transliterator::HashTransliterator
rule.
A transliterator which accepts a Hash of characters as its translation
def add(hash)
def add(hash) hash.keys.each do |key| utf8_key = key.to_s.dup.force_encoding('UTF-8') hash[utf8_key] = hash.delete(key).to_s end approximations.merge! hash end
def approximations
def approximations @approximations ||= {} end
def initialize(rule = nil)
def initialize(rule = nil) @rule = rule add DEFAULT_APPROXIMATIONS.dup add rule if rule end
def transliterate(string, replacement = nil)
def transliterate(string, replacement = nil) string.gsub(/[^\x00-\x7f]/u) do |char| approximations[char] || replacement || DEFAULT_REPLACEMENT_CHAR end end