From 13e54bca3d524b4b43d5e2807ee643181ca78ce1 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Mon, 13 May 2019 22:07:42 +0200 Subject: [PATCH] DEV: Add specs for handling InvalidPluralizationData exception follow-up to 6d44be51 --- spec/components/discourse_i18n_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/components/discourse_i18n_spec.rb b/spec/components/discourse_i18n_spec.rb index 19118eaeda4..0215dc33fee 100644 --- a/spec/components/discourse_i18n_spec.rb +++ b/spec/components/discourse_i18n_spec.rb @@ -94,4 +94,23 @@ describe I18n::Backend::DiscourseI18n do expect(backend.exists?(:ru, :bogus)).to eq(false) end end + + describe '#pluralize' do + it 'uses fallback locales when a pluralization key is missing' do + SiteSetting.default_locale = 'ru' + + backend.store_translations(:ru, items: { one: '%{count} Russian item', other: '%{count} Russian items' }) + + expect(backend.translate(:ru, :items, count: 1)).to eq('1 Russian item') + expect(backend.translate(:ru, :items, count: 2)).to eq('2 items') + expect(backend.translate(:ru, :items, count: 5)).to eq('5 Russian items') + + backend.store_translations(:ru, items: { one: '%{count} Russian item', few: '%{count} Russian items are a few', other: '%{count} Russian items' }) + expect(backend.translate(:ru, :items, count: 2)).to eq('2 Russian items are a few') + + backend.store_translations(:en, airplanes: { one: '%{count} airplane' }) + expect(backend.translate(:ru, :airplanes, count: 1)).to eq('1 airplane') + expect { backend.translate(:ru, :airplanes, count: 2) }.to raise_error(I18n::InvalidPluralizationData) + end + end end