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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

default: nil breaks fallbacks #386

Closed
daniel-rikowski opened this issue Oct 10, 2017 · 0 comments 路 Fixed by #387
Closed

default: nil breaks fallbacks #386

daniel-rikowski opened this issue Oct 10, 2017 · 0 comments 路 Fixed by #387

Comments

@daniel-rikowski
Copy link

daniel-rikowski commented Oct 10, 2017

I've noticed that using default: nil with fallbacks leads to breaking the fallback chain.

Given these translations:

de:
  bar: 'Bar from de'
en:
  bar: 'Bar from en'

I18n.t('bar', locale: :'de-DE', default: '') returns 'Bar from de' 馃憤
I18n.t('bar', locale: :'de-DE', default: nil) returns nil 馃憥

This is caused by the return statement in this code from fallbacks.rb: (simplified for readability)

I18n.fallbacks[locale].each do |fallback|
  result = super(fallback, key, options)
  # PROBLEMATIC STATEMENT:
  return result if (result.nil? && options.key?(:default) && options[:default].nil?) || !result.nil?
end

In other words: If you have a default of nil and the first fallback locale doesn't return a value, the default is applied immediately. The loop is exited and no further fallbacks are tried.

The solution is to delay the default check until all fallbacks are tried.

I've prepared a PR with a failing test case for this problem. See #387

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

Successfully merging a pull request may close this issue.

1 participant