diff options
author | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-30 01:07:10 +0400 |
---|---|---|
committer | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-30 01:30:20 +0400 |
commit | b56838e5b11455ca765b2be62265d6d4b5ab6d7c (patch) | |
tree | 29f50391ba6fc60b9767a83dc2af6eb60b913e68 /lib | |
parent | e345f2dcbc86dfa6331d985027b2aeeb833a6af5 (diff) |
Fall back to english on MissingInterpolationError
Diffstat (limited to 'lib')
-rw-r--r-- | lib/i18n_interpolation_fallbacks.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/i18n_interpolation_fallbacks.rb b/lib/i18n_interpolation_fallbacks.rb new file mode 100644 index 000000000..45c6dfe59 --- /dev/null +++ b/lib/i18n_interpolation_fallbacks.rb @@ -0,0 +1,24 @@ +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 |