module I18n::Base
def transliterate(key, throw: false, raise: false, locale: nil, replacement: nil, **options)
I18n.transliterate("Jürgen", :locale => :en) # => "Jurgen"
I18n.transliterate("Jürgen") # => "Juergen"
I18n.locale = :de
I18n.transliterate("Jürgen") # => "Jurgen"
I18n.locale = :en
Transliterating strings:
store_translations(:xx, :i18n => {:transliterate => {:rule => translit})
translit = lambda {|string| MyTransliterator.transliterate(string) }
Setting a Proc:
})
}
}
'ö' => 'oe'
'ü' => 'ue',
rule: {
transliterate: {
store_translations(:de, i18n: {
Setting a Hash using Ruby:
ö: "oe"
ü: "ue"
rule:
transliterate:
i18n:
Setting a Hash in
*Examples*
rules, while Procs do not.
single string argument. Hash rules inherit the default transliteration
Transliteration rules can either be a Hash or a Proc. Procs must accept a
i18n.transliterate.rule.
expects transliteration rules to be stored at
It's also possible to add support for per-locale transliterations. I18n
# => "???"
I18n.transliterate("日本語")
# => "AEroskobing"
I18n.transliterate("Ærøskøbing")
transliterate only Latin strings to an ASCII approximation:
Transliterates UTF-8 characters to ASCII. By default this method will
def transliterate(key, throw: false, raise: false, locale: nil, replacement: nil, **options) locale ||= config.locale raise Disabled.new('transliterate') if locale == false enforce_available_locales!(locale) config.backend.transliterate(locale, key, replacement) rescue I18n::ArgumentError => exception handle_exception((throw && :throw || raise && :raise), exception, locale, key, options) end