-
-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I18n::Backend::Chain does not support pluralization split between different backends #493
Comments
We are facing the same issue using only The strategy to Would it be possible to I propose the following changes #502. |
I am able to reproduce this issue with this small Ruby script: require 'bundler'
Bundler.setup
require 'i18n'
require 'pry'
def backend(translations)
backend = I18n::Backend::Simple.new
translations.each { |locale, data| backend.store_translations(locale, data) }
backend
end
main_backend = backend({ en: { plural: { one: "1" } }})
fallback_backend = backend({ en: { plural: { other: "%{count}" } } })
I18n.backend = I18n::Backend::Chain.new(main_backend, fallback_backend)
p I18n.t(:plural, count: 2) I will take a look into this a little later on. |
A PR to fix this issue would be welcome :) |
Hi @radar. Another approach would be to add |
To make it simple, I am using part of the test file
tests/backend/chain_test.rb
to demonstrate the issue.What I tried to do
I18n::Backend::Chain
is used for two different backends (regardless of types). Two backends (main, and fallback) contain the same translation key but with non-overlapping pluralization (i.e.one
andother
).What I expected to happen
What actually happened
Versions of i18n, rails, and anything else you think is necessary
1.7.0
(current master)Why it does happen
It seems that
I18n::Backend::Chain#translate
andI18n::Backend::Chain#translate
rely onthrow
andcatch
mechanism whileI18n::Backend::Base#pluralize
usesraise
.I18n::Backend::Chain#translate
tries to loop over available backends and usescatch(:exception)
to control the flow if a translation is missing (i.e. move to the next available backend). It does miss out on a case when the pluralization has not been available for one backend,InvalidPluralizationData
exception is raised, but notthrow
.I've been thinking about using
begin
andrescue
wrapped around thecatch(:exception)
somehow similar to what we have inI18n::Backend::Fallbacks#translate
Please let me know if this is a good idea. Happy to send a PR for review and further discussion 😁.
The text was updated successfully, but these errors were encountered: