From 038eb6f645b55e984fb8c4e3980b1d4aae018d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 24 Aug 2016 11:53:03 +0200 Subject: [PATCH] FIX: translations with a symbol as key should also be overridable --- lib/freedom_patches/translate_accelerator.rb | 8 +++----- .../translate_accelerator_spec.rb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 spec/components/freedom_patches/translate_accelerator_spec.rb diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rb index c5e8abf3a..8b734f9c8 100644 --- a/lib/freedom_patches/translate_accelerator.rb +++ b/lib/freedom_patches/translate_accelerator.rb @@ -90,7 +90,6 @@ module I18n key = args.shift locale = options[:locale] || config.locale - @cache ||= LruRedux::ThreadSafeCache.new(LRU_CACHE_SIZE) k = "#{key}#{locale}#{config.backend.object_id}" @@ -122,7 +121,7 @@ module I18n end end - by_site[locale] + by_site[locale].with_indifferent_access end def client_overrides_json(locale) @@ -138,8 +137,7 @@ module I18n load_locale(locale) unless @loaded_locales.include?(locale) if @overrides_enabled - by_locale = overrides_by_locale(locale) - if by_locale + if by_locale = overrides_by_locale(locale) if options.present? options[:overrides] = by_locale @@ -152,9 +150,9 @@ module I18n return result end end - end end + translate_no_override(key, options) end diff --git a/spec/components/freedom_patches/translate_accelerator_spec.rb b/spec/components/freedom_patches/translate_accelerator_spec.rb new file mode 100644 index 000000000..6fef757ee --- /dev/null +++ b/spec/components/freedom_patches/translate_accelerator_spec.rb @@ -0,0 +1,17 @@ +require "rails_helper" + +describe "translate accelerator" do + + it "overrides for both string and symbol keys" do + key = "user.email.not_allowed" + text_overriden = "foobar" + + expect(I18n.t(key)).to be_present + + TranslationOverride.upsert!("en", key, text_overriden) + + expect(I18n.t(key)).to eq(text_overriden) + expect(I18n.t(key.to_sym)).to eq(text_overriden) + end + +end