mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
PERF: bypass slow locale lookups in various cases
Previously as soon as any override was defined we would regress to the slow path for locale lookups. Additionally if `raise: true` was specified which rails likes to add in views we would bypass the cache The new design manages to use the fast path for many more cases
This commit is contained in:
@ -24,6 +24,15 @@ describe "translate accelerator" do
|
||||
expect(override.persisted?).to eq(true)
|
||||
end
|
||||
|
||||
it "supports raising if requested, and cache bypasses" do
|
||||
expect { I18n.t('i_am_an_unknown_key99', raise: true) }.to raise_error(I18n::MissingTranslationData)
|
||||
|
||||
orig = I18n.t('i_am_an_unknown_key99')
|
||||
|
||||
expect(I18n.t('i_am_an_unknown_key99').object_id).to eq(orig.object_id)
|
||||
expect(I18n.t('i_am_an_unknown_key99')).to eq("translation missing: en_US.i_am_an_unknown_key99")
|
||||
end
|
||||
|
||||
it "overrides for both string and symbol keys" do
|
||||
key = 'user.email.not_allowed'
|
||||
text_overriden = 'foobar'
|
||||
@ -124,6 +133,7 @@ describe "translate accelerator" do
|
||||
I18n.overrides_disabled do
|
||||
expect(I18n.t('title')).to eq(orig_title)
|
||||
end
|
||||
|
||||
expect(I18n.t('title')).to eq('overridden title')
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user