Skip to content
Extraits de code Groupes Projets
Valider b56838e5 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Fall back to english on MissingInterpolationError

parent e345f2dc
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -14,3 +14,5 @@ AVAILABLE_LANGUAGE_CODES.each do |c|
I18n.fallbacks[c.to_sym] = [c.to_sym, DEFAULT_LANGUAGE.to_sym, :en]
end
end
require 'i18n_interpolation_fallbacks'
I18n::Backend::Simple.send(:include, I18n::Backend::InterpolationFallbacks)
module I18n
module Backend
module InterpolationFallbacks
def translate(locale, key, options = {})
return super if options[:fallback]
default = extract_string_or_lambda_default!(options) if options[:default]
options[:fallback] = true
I18n.fallbacks[locale].each do |fallback|
begin
result = super(fallback, key, options)
return result unless result.nil?
rescue I18n::MissingInterpolationArgument
end
end
options.delete(:fallback)
return super(locale, nil, options.merge(:default => default)) if default
raise(I18n::MissingInterpolationError.new(locale, key, options))
end
end
end
end
......@@ -62,4 +62,19 @@ describe 'making sure the spec runner works' do
end
end
describe I18n do
include ActionView::Helpers::TranslationHelper
it 'MissingInterpolationError in a non-english locale is not fatal' do
I18n.locale = 'it'
I18n.backend.should_receive(:lookup).ordered.
with(:it, 'bob', nil, :hey => "what", :fallback => true).
and_return("%{not_present} failure")
I18n.backend.should_receive(:lookup).ordered.
with(:en, 'bob', nil, :hey => "what", :fallback => true).
and_return("English translation")
translation = translate('bob', :hey => "what")
translation.should == "English translation"
end
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter