-
-
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
allow disabling fallback explicitly when calling translate #354
Conversation
seems like test is broken in master too, opened a separate PR to fix it at #355 .. will rebase later.. |
Does |
e.g I18n.translate(:key, :fallback => false)
37267b8
to
9481e94
Compare
nope, as far as I can tell, |
@ignatiusreza Would you please be able to provide me with a small reproduction repo that I could use to investigate this issue? I think you'd be better at coming up with one than me because it sounds like you understand what's happening here. Please provide steps to reproduce the issue and expected/actual outcomes as well. From that point I should have enough information to investigate. Thanks! |
Sure @radar ! Would something like the following be okay? begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# use this to see test #2 pass, while #1 & #3 fails
gem "i18n"
# use this to see test #3 pass, while #1 & #2 fails
# gem "i18n", github: 'ignatiusreza/i18n', branch: 'disable_fallback'
gem "minitest"
gem "test_declarative"
end
require "i18n"
require "minitest/autorun"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
class I18nBackendFallbacksTranslateTest < Minitest::Test
# ehem.. I don't actually suck, but it's easier to follow if the test are sorted.. :p
i_suck_and_my_tests_are_order_dependent!
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
def setup
super
I18n.enforce_available_locales = false
I18n.backend = Backend.new
I18n.backend.store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en')
I18n.backend.store_translations(:de, :bar => 'Bar in :de')
end
def teardown
I18n.locale = nil
I18n.default_locale = nil
I18n.load_path = nil
I18n.available_locales = nil
I18n.backend = nil
I18n.default_separator = nil
I18n.enforce_available_locales = true
super
end
test "1. disable fallback using :fallbacks => []" do
# syntax taken from wiki, but it doesn't works
# ref: https://github.com/svenfuchs/i18n/wiki/Fallbacks#providing-a-default
assert_equal 'Default Foo', I18n.t(:foo, :locale => :de, :default => 'Default Foo', :fallbacks => [])
end
test "2. disable fallback using :fallback => true" do
# side effect of modifying options[:fallback]
# ref: https://github.com/svenfuchs/i18n/commit/957145ef85875b913a93502111368b4fc2c67fd5
assert_equal 'Default Foo', I18n.t(:foo, :locale => :de, :default => 'Default Foo', :fallback => true)
end
test "3. disable fallback using :fallback => false" do
# suggested approach
# ref: https://github.com/svenfuchs/i18n/pull/354
assert_equal 'Default Foo', I18n.t(:foo, :locale => :de, :default => 'Default Foo', :fallback => false)
end
end |
Thank you @ignatiusreza. This is excellent. I don't see anywhere in the code that uses the passed-in I have taken a look at this issue this morning and I can't figure out how to fix it without breaking other things. Maybe someone smarter than me can figure it out? |
I'm sorry, but could you help clarify in what you meant by if you're worried about making |
Sorry, I had forgotten this was a PR and I was writing those replies on my phone. Now that I'm on a computer, I can see better :) Sorry for that confusion. The code looks great and the tests are all happy, and so am I :) |
not a problem.. thanks for the merge 👍 |
We were using |
@jbourassa Thanks for the comment and for updating the wiki :) |
e.g. by doing
I18n.translate(:key, :fallback => false)
note that currently, we sort of able to do this by doing
I18n.translate(:key, :fallback => true)
, which are quite a confusing behavior, introduced -- I assumed -- unintentionally because we're modifying options.. so this PR does have backward incompatibility changes, even though it's one that was not officially supported before?another note is, in the wiki for fallbacks, we have something like:
which does not seems to works.. if what the wiki is saying is the preferred way for supporting disabling fallback, I'm happy to change this PR to do just that, though, I must say that having both
fallback
andfallbacks
as part of the options will be confusing..