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