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

Rails 4.2.1 breaks if there is a nil and a string in the default translations #19419

Closed
jcoyne opened this issue Mar 19, 2015 · 7 comments
Closed

Comments

@jcoyne
Copy link
Contributor

jcoyne commented Mar 19, 2015

In rails 4.2.0 I could do this:

    t(:"try_this", default: [:"how_about.this", nil, "Finally this")

and if :"try_this" and :"how_about.this" are not found in the locale file, then "Finally this" would be returned.

In Rails 4.2.1 I get:

     ActionView::Template::Error:
       translation missing: en.Finally this
@jcoyne
Copy link
Contributor Author

jcoyne commented Mar 19, 2015

This behavior is documented here in section 4.1.2: http://guides.rubyonrails.org/i18n.html#looking-up-translations

@rafaelfranca
Copy link
Member

Thanks. I believe it is related with #18308 or with the fix of one regression that this PR caused #19102.

@jcoyne
Copy link
Contributor Author

jcoyne commented Mar 19, 2015

Yeah, I think I broke it in 90fcfea and I'll try to fix/test this case.

jcoyne added a commit to projectblacklight/blacklight that referenced this issue Mar 19, 2015
@jcoyne jcoyne changed the title Rails 4.2.1 breaks default string translations Rails 4.2.1 breaks if there is a nil and a string in the default translations Mar 19, 2015
jcoyne added a commit to jcoyne/rails that referenced this issue Mar 19, 2015
@jcoyne
Copy link
Contributor Author

jcoyne commented Mar 20, 2015

After doing some bisecting, this error was introduced by 362557e.

jcoyne added a commit to projectblacklight/blacklight that referenced this issue Mar 20, 2015
jcoyne added a commit to jcoyne/rails that referenced this issue Mar 20, 2015
rafaelfranca added a commit that referenced this issue Mar 20, 2015
Strip nils out of default translations. Fixes #19419
rafaelfranca added a commit that referenced this issue Mar 20, 2015
Strip nils out of default translations. Fixes #19419
rafaelfranca added a commit that referenced this issue Mar 20, 2015
Strip nils out of default translations. Fixes #19419
jcoyne added a commit to projectblacklight/blacklight that referenced this issue Mar 23, 2015
jcoyne added a commit to projectblacklight/blacklight that referenced this issue Mar 23, 2015
cbeer added a commit to projectblacklight/blacklight that referenced this issue Mar 23, 2015
jcoyne added a commit to projectblacklight/blacklight that referenced this issue Mar 23, 2015
cbeer added a commit to projectblacklight/blacklight that referenced this issue Mar 23, 2015
cbeer added a commit to projectblacklight/blacklight that referenced this issue Mar 23, 2015
cbeer added a commit to projectblacklight/blacklight that referenced this issue Mar 23, 2015
cbeer added a commit to projectblacklight/blacklight that referenced this issue Mar 26, 2015
@aprescott
Copy link
Contributor

I'm wondering why this issue was closed. Is it still considered a regression bug? Was it fixed in a separate PR?

I have a problem that looks to be related to this. We had some code that uses default: [[]] because we want the default to be [] if nothing is found. This broke in 4.2.1 because 4.2.1 made changes to the way that default: [[]] is "unwrapped" to [] (because it uses options.delete and then re-adds it with options[:delete]=).

class NestedArrayTest
  include ActionView::Helpers::TranslationHelper

  def translate(key, options = {})
    default = super

    super(key, options.merge(scope: "this.does.not.exist", default: [[]]))
  end
  alias_method :t, :translate
end

class SimpleArrayTest
  include ActionView::Helpers::TranslationHelper

  def translate(key, options = {})
    default = super

    super(key, options.merge(scope: "this.does.not.exist", default: []))
  end
  alias_method :t, :translate
end
# pre-4.2.1
NestedArrayTest.new.translate("lol") #=> []
SimpleArrayTest.new.translate("lol") #=> translation missing <span>

# 4.2.1
NestedArrayTest.new.translate("lol") #=> translation missing <span>
SimpleArrayTest.new.translate("lol") #=> translation missing <span>

@jcoyne
Copy link
Contributor Author

jcoyne commented Apr 3, 2015

@aprescott see #19421

@aprescott
Copy link
Contributor

Ah, thanks! It looks like my problem still exists. I'll open a PR/issue if it's still broken on 4-2-stable/master.

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

3 participants