I18n::Backend
Inherits Reference / Object
Backend is a storage for translations. All translations are stored in #data.
backend = I18n::Backends::YAML.new
backend.load_paths << Dir.current + "/locales"
backend.load
backend.translate(["hello", "world"], "en") # => "Hello world!"
Class methods
quantity_key_procs
A list of QuantityKeyProcs associated with their locales.
Defaults with "en" key:
"en" => QuantityKeyProc.new do |count|
if count == 0
"zero"
elsif count == 1
"one"
else
"other"
end
end
Extend it with your own locales if you need:
I18n::Backend.quantity_key_procs.merge!({"ru" => QuantityKeyProc.new { |count| your_code }})
Instance methods
translate(keys : Array(String), locale : String, count : Int32 | Nil = nil)
Find a translation by keys and locale.
locale is prepended to the list of keys when searching for a translation.
# Searches for "en => hello => world"
backend.translate(["hello", "world"], "en") # => "Hello world!"
# Searches for "en => apples => other"
backend.translate(["apples"], "en", count: 3) # => "3 apples"