Skip to content

Commit

Permalink
Fixes #369 thread issue when calling translate with fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Schroeder committed Jun 14, 2017
1 parent 46d9432 commit abd1ae0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/i18n/backend/fallbacks.rb
Expand Up @@ -36,11 +36,11 @@ module Fallbacks
# it is evaluated last after all the fallback locales have been tried.
def translate(locale, key, options = {})
return super unless options.fetch(:fallback, true)
return super if (@fallback_locked ||= false)
return super if options[:fallback_in_progress]
default = extract_non_symbol_default!(options) if options[:default]

begin
@fallback_locked = true
options[:fallback_in_progress] = true
I18n.fallbacks[locale].each do |fallback|
begin
catch(:exception) do
Expand All @@ -52,7 +52,7 @@ def translate(locale, key, options = {})
end
end
ensure
@fallback_locked = false
options.delete(:fallback_in_progress)
end

return super(locale, nil, options.merge(:default => default)) if default
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tests/localization/procs.rb
Expand Up @@ -72,7 +72,7 @@ def self.inspect_args(args)
when ::Date
arg.strftime('%a, %d %b %Y')
when Hash
arg.delete(:fallback)
arg.delete(:fallback_in_progress)
arg.inspect
else
arg.inspect
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tests/procs.rb
Expand Up @@ -48,7 +48,7 @@ module Procs


def self.filter_args(*args)
args.map {|arg| arg.delete(:fallback) if arg.is_a?(Hash) ; arg }.inspect
args.map {|arg| arg.delete(:fallback_in_progress) if arg.is_a?(Hash) ; arg }.inspect
end
end
end
Expand Down

0 comments on commit abd1ae0

Please sign in to comment.