FIX: translations with a symbol as key should also be overridable

This commit is contained in:
Régis Hanol 2016-08-24 11:53:03 +02:00
parent c1f516a604
commit 038eb6f645
2 changed files with 20 additions and 5 deletions

View file

@ -90,7 +90,6 @@ module I18n
key = args.shift key = args.shift
locale = options[:locale] || config.locale locale = options[:locale] || config.locale
@cache ||= LruRedux::ThreadSafeCache.new(LRU_CACHE_SIZE) @cache ||= LruRedux::ThreadSafeCache.new(LRU_CACHE_SIZE)
k = "#{key}#{locale}#{config.backend.object_id}" k = "#{key}#{locale}#{config.backend.object_id}"
@ -122,7 +121,7 @@ module I18n
end end
end end
by_site[locale] by_site[locale].with_indifferent_access
end end
def client_overrides_json(locale) def client_overrides_json(locale)
@ -138,8 +137,7 @@ module I18n
load_locale(locale) unless @loaded_locales.include?(locale) load_locale(locale) unless @loaded_locales.include?(locale)
if @overrides_enabled if @overrides_enabled
by_locale = overrides_by_locale(locale) if by_locale = overrides_by_locale(locale)
if by_locale
if options.present? if options.present?
options[:overrides] = by_locale options[:overrides] = by_locale
@ -152,9 +150,9 @@ module I18n
return result return result
end end
end end
end
end
end
end
translate_no_override(key, options) translate_no_override(key, options)
end end

View file

@ -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