mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
PERF: Much more performant, multisite aware I18n overrides
This commit is contained in:
parent
711a7a146c
commit
e168c5fde3
10 changed files with 108 additions and 36 deletions
|
@ -7,17 +7,22 @@ describe I18n::Backend::DiscourseI18n do
|
|||
let(:backend) { I18n::Backend::DiscourseI18n.new }
|
||||
|
||||
before do
|
||||
backend.reload!
|
||||
backend.store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en')
|
||||
I18n.reload!
|
||||
backend.store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :wat => "Hello %{count}")
|
||||
backend.store_translations(:en, :items => {:one => 'one item', :other => "%{count} items" })
|
||||
backend.store_translations(:de, :bar => 'Bar in :de')
|
||||
backend.store_translations(:'de-AT', :baz => 'Baz in :de-AT')
|
||||
end
|
||||
|
||||
after do
|
||||
I18n.reload!
|
||||
end
|
||||
|
||||
it 'translates the basics as expected' do
|
||||
expect(backend.translate(:en, 'foo')).to eq("Foo in :en")
|
||||
expect(backend.translate(:en, 'items', count: 1)).to eq("one item")
|
||||
expect(backend.translate(:en, 'items', count: 3)).to eq("3 items")
|
||||
expect(backend.translate(:en, 'wat', count: 3)).to eq("Hello 3")
|
||||
end
|
||||
|
||||
describe '#exists?' do
|
||||
|
@ -53,16 +58,38 @@ describe I18n::Backend::DiscourseI18n do
|
|||
end
|
||||
|
||||
describe 'with overrides' do
|
||||
before do
|
||||
it 'returns the overriden key' do
|
||||
TranslationOverride.upsert!('en', 'foo', 'Overwritten foo')
|
||||
end
|
||||
|
||||
it 'returns the overrided key' do
|
||||
expect(backend.translate(:en, 'foo')).to eq('Overwritten foo')
|
||||
expect(I18n.translate('foo')).to eq('Overwritten foo')
|
||||
|
||||
TranslationOverride.upsert!('en', 'foo', 'new value')
|
||||
backend.reload!
|
||||
expect(backend.translate(:en, 'foo')).to eq('new value')
|
||||
I18n.reload!
|
||||
expect(I18n.translate('foo')).to eq('new value')
|
||||
end
|
||||
|
||||
it 'supports disabling' do
|
||||
TranslationOverride.upsert!('en', 'foo', 'meep')
|
||||
|
||||
I18n.overrides_disabled do
|
||||
expect(I18n.translate('foo')).to eq('meep')
|
||||
end
|
||||
end
|
||||
|
||||
it 'supports interpolation' do
|
||||
TranslationOverride.upsert!('en', 'foo', 'hello %{world}')
|
||||
expect(I18n.translate('foo', world: 'foo')).to eq('hello foo')
|
||||
end
|
||||
|
||||
it 'supports interpolation named count' do
|
||||
TranslationOverride.upsert!('en', 'wat', 'goodbye %{count}')
|
||||
expect(I18n.translate('wat', count: 123)).to eq('goodbye 123')
|
||||
end
|
||||
|
||||
it 'supports one and other' do
|
||||
TranslationOverride.upsert!('en', 'items.one', 'one fish')
|
||||
TranslationOverride.upsert!('en', 'items.other', '%{count} fishies')
|
||||
expect(I18n.translate('items', count: 13)).to eq('13 fishies')
|
||||
expect(I18n.translate('items', count: 1)).to eq('one fish')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue