Skip to content
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

A false default is inconsistent #379

Closed
jcoyne opened this issue Jul 21, 2017 · 5 comments
Closed

A false default is inconsistent #379

jcoyne opened this issue Jul 21, 2017 · 5 comments

Comments

@jcoyne
Copy link

jcoyne commented Jul 21, 2017

What I tried to do

Passing a default with a single element array containing false seems to not give any default behavior. This is inconsistent with a default of false(no wrapping array) or an array of strings.
I believe this is a regression in 0.8.3.

I18n.translate('foo', default: [false])
=> "translation missing: en.foo"
I18n.translate('foo', default: false)
 => false
I18n.translate('foo', default: ['duh'])
"duh"

This is a problem for me because when I use the rails' TranslationHelper#t method, it wraps the default in an array automatically.

What I expected to happen

I18n.translate('foo', default: [false])
=> false

What actually happened

I18n.translate('foo', default: [false])
=> "translation missing: en.foo"

Versions of i18n, rails, and anything else you think is neccessary

version 0.8.6 has this problem. I believe this behavior was changed in 0.8.3


Bonus points for providing an application or a small code example which reproduces the issue.

Thanks! ❤️

@radar
Copy link
Collaborator

radar commented Jul 25, 2017

Hi @jcoyne, thanks for getting in touch.

I am unable to reproduce this issue within a new Rails app. I am using i18n 0.8.6 and Rails 5.1.2.

I've created a new view and I've put this content in it:

<%= t(:foo, default: false) %>
<%= t(:foo, default: [false]) %>

Both return "false" for me. I do not see this "translation missing" error as you've shown.

Could you please provide me with an application which reproduces this issue?

Thanks!

@radar
Copy link
Collaborator

radar commented Oct 15, 2017

@jcoyne Please provide steps to reproduce this, otherwise I will be marking this issue as stale and closing it.

@jdelStrother
Copy link

I see this in a fresh Rails 5.1.4 install, with i18n 0.9.1

rails51.zip

For me, t("foos", default: false) returns '<span class="translation_missing" title="translation missing: en.false">False</span>'.

However, I18n.t("foos", default: false) returns false, suggesting the problem is with Rails when combined with i18n >= 0.8.3. If I lower the i18n gem version to 0.8.1, both t() and I18n.t() return false.

@radar
Copy link
Collaborator

radar commented Dec 12, 2017

Thank you for filing this issue. I do not have any available time atm to investigate it. If you're not seeing this bug with Rails but you are seeing this bug with Rails then I would consider that a Rails bug. You should file an issue on their repo also, and link this issue to it.

@rafaelfranca
Copy link
Contributor

I tried with only i18n and I could reproduce this issue:

>> require 'i18n'
=> true
>> I18n::VERSION
=> "0.9.1"
>> I18n.config.enforce_available_locales = false
=> false
>> I18n.t("foo", default: [false])
=> "translation missing: en.foo"
>> I18n.t("foo", default: false)
=> false

I also tested with 0.8.1 and this behavior is the same:

>> gem 'i18n', '0.8.1'
=> true
>> require 'i18n'
=> true
>> I18n::VERSION
=> "0.8.1"
>> I18n.config.enforce_available_locales = false
=> false
>> I18n.t("foo", default: [false])
=> "translation missing: en.foo"
>> I18n.t("foo", default: false)
=> false
>> exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants