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
t("foo", default: false) doesn't respect the default #31426
Comments
@jdelStrother could you reproduce with an executable script based on https://github.com/rails/rails/blob/master/guides/bug_report_templates/generic_gem.rb ? |
Will see what I can do |
I think the issue is with Array being passed as an option here in the Rails helper. And then, the helper transforms it to the message |
FWIW, a simple test case. For me, flipping between i18n 0.8.1 & 0.8.3 will fix/break the test. # frozen_string_literal: true
gem "bundler", "< 1.16"
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"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", tag: 'fd1304d'
# gem "i18n", "0.8.1"
gem "i18n", "0.8.3"
end
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get "/" => "test#index"
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render inline: "<%= t(:foo, default: false) || 'no default' %>"
end
end
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_default_false_translations_should_return_false
assert I18n.t(:foo, default: false) == false
get "/"
assert_equal "no default", last_response.body
end
private
def app
Rails.application
end
end |
If that is the case this is a i18n issue since they changed the behavior in a patch version. |
Opened PR on i18n side ruby-i18n/i18n#399. |
Fixed with ruby-i18n/i18n#399 |
Steps to reproduce
Try to translate a key, supplying a default of
false
( egt("foo", default: false)
).Expected behavior
If the translation is missing, it returns
false
Actual behavior
If the translation is missing, it returns
<span class="translation_missing" title="translation missing: en.false">False</span>
This is also demonstrated in this sample project:
rails51.zip
System configuration
Rails version:
5.1.4
Ruby version:
2.3.4
This appears to be a change in the i18n gem since 0.8.3 - if you downgrade to 0.8.1,
t("foo", default: false)
returnfalse
.However, the problem only occurs if you use Rails
t
helper - if you go viaI18n.t("foo", default: false)
, it returns false regardless of the i18n version.This was originally filed on the i18n repo at ruby-i18n/i18n#379.
The text was updated successfully, but these errors were encountered: