From 17f75bbe920545bdc05a9a96f374cf9099468cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 26 Feb 2014 18:42:16 +0100 Subject: [PATCH] BUGFIX: fallback to en translation when interpolation is missing --- lib/freedom_patches/translate_accelerator.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rb index 88d06b35fe2..e878e3374e9 100644 --- a/lib/freedom_patches/translate_accelerator.rb +++ b/lib/freedom_patches/translate_accelerator.rb @@ -13,12 +13,20 @@ module I18n def translate(*args) @cache ||= LruRedux::ThreadSafeCache.new(LRU_CACHE_SIZE) found = true - k = [args,config.locale,config.backend.object_id] - t = @cache.fetch(k){found=false} + k = [args, config.locale, config.backend.object_id] + t = @cache.fetch(k) { found = false } unless found - t = @cache[k] = translate_no_cache(*args).freeze + begin + t = translate_no_cache(*args) + rescue MissingInterpolationArgument + options = args.last.is_a?(Hash) ? args.pop.dup : {} + options.merge!(locale: config.default_locale) + key = args.shift + t = translate_no_cache(key, options) + ensure + t = @cache[k] = t.freeze + end end - t end