This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
The chained backend
Overview
The chained backend class allows to use multiple backends for translation and localization.
It loops through all the backends in the order they were added to the chain.
Example
module I18n
module Backend
class RussianLocalization
def localize(locale, object, format = :default)
return nil unless locale.to_s == 'ru-RU'
# add Russian localization code here ...
end
end
end
end
I18n.backend = I18n::Backend::Chain.new
I18n.backend.add I18n::Backend::RussianLocalization.new
I18n.backend.add I18n::Backend::Simple.new
Chaining
Backends can be added to the chain as an instances, classes or symbols:
I18n.chain_backends I18n::Backend::Simple.new, I18n::Backend::Simple, :simple
The following also works
I18n::Backend::Chain.new I18n::Backend::Simple.new, I18n::Backend::Simple, :simple
Backends can be also added to an existing chain
I18n.backend.add I18n::Backend::Simple.new, I18n::Backend::Simple, :simple
Translating
The backend returns the first match as a result for a standard translating.
In the case of bulk translation and namespace lookup the backend chain receives and returns translations from all backends.
If no result was found I18n::MissingTranslationData error is raised.
I18n.t :foo
I18n.t [:foo, :bar]
Localizing
The chained backend returns the first hit as a result of localization. Therefore backends need to return nil when they can’t localize the
passed object.
I18n.l Time.now






