Module: I18n::Backend::Transliterator

Included in:
Base
Defined in:
lib/i18n/backend/transliterator.rb

Defined Under Namespace

Classes: HashTransliterator, ProcTransliterator

Constant Summary collapse

DEFAULT_REPLACEMENT_CHAR =
"?"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(rule = nil) ⇒ Object

Get a transliterator instance.



19
20
21
22
23
24
25
26
27
# File 'lib/i18n/backend/transliterator.rb', line 19

def self.get(rule = nil)
  if !rule || rule.kind_of?(Hash)
    HashTransliterator.new(rule)
  elsif rule.kind_of? Proc
    ProcTransliterator.new(rule)
  else
    raise I18n::ArgumentError, "Transliteration rule must be a proc or a hash."
  end
end

Instance Method Details

#transliterate(locale, string, replacement = nil) ⇒ Object

Given a locale and a UTF-8 string, return the locale’s ASCII approximation for the string.



11
12
13
14
15
16
# File 'lib/i18n/backend/transliterator.rb', line 11

def transliterate(locale, string, replacement = nil)
  @transliterators ||= {}
  @transliterators[locale] ||= Transliterator.get I18n.t(:'i18n.transliterate.rule',
    :locale => locale, :resolve => false, :default => {})
  @transliterators[locale].transliterate(string, replacement)
end