A platform for community discussion. Free, open, simple.
FIX: Display site text overrides for non '_MF' keys (#8189)
Mark VanLandinghambd969332e0b4
diff --git a/app/assets/javascripts/discourse/components/expanding-text-area.js.es6 b/app/assets/javascripts/discourse/components/expanding-text-area.js.es6index 064764713fc..7008eb1d013 100644--- a/app/assets/javascripts/discourse/components/expanding-text-area.js.es6+++ b/app/assets/javascripts/discourse/components/expanding-text-area.js.es6@@ -12,6 +12,7 @@ export default Ember.TextArea.extend({@observes("value")_updateAutosize() {+ this.element.value = this.value;const evt = document.createEvent("Event");evt.initEvent("autosize:update", true, false);this.element.dispatchEvent(evt);diff --git a/app/controllers/admin/site_texts_controller.rb b/app/controllers/admin/site_texts_controller.rbindex 756974c109e..ef594471d9f 100644--- a/app/controllers/admin/site_texts_controller.rb+++ b/app/controllers/admin/site_texts_controller.rb@@ -109,7 +109,7 @@ class Admin::SiteTextsController < Admin::AdminControllervalue = override&.firstend- value ||= I18n.t(key, default: '')+ value ||= I18n.t(key){ id: key, value: value }enddiff --git a/app/models/translation_override.rb b/app/models/translation_override.rbindex 9dcf7189192..95e4183589b 100644--- a/app/models/translation_override.rb+++ b/app/models/translation_override.rb@@ -65,8 +65,10 @@ class TranslationOverride < ActiveRecord::Baseprivatedef check_interpolation_keys+ transformed_key = transform_pluralized_key(translation_key)+original_text = I18n.overrides_disabled do- I18n.t(translation_key, locale: :en)+ I18n.t(transformed_key, locale: :en)endif original_text@@ -76,7 +78,7 @@ class TranslationOverride < ActiveRecord::Basecustom_interpolation_keys = []CUSTOM_INTERPOLATION_KEYS_WHITELIST.select do |key, value|- if self.translation_key.start_with?(key)+ if transformed_key.start_with?(key)custom_interpolation_keys = valueendend@@ -96,6 +98,10 @@ class TranslationOverride < ActiveRecord::Baseendend+ def transform_pluralized_key(key)+ match = key.match(/(.*)\.(zero|two|few|many)$/)+ match ? match.to_a.second + '.other' : key+ endend# == Schema Informationdiff --git a/spec/models/translation_override_spec.rb b/spec/models/translation_override_spec.rbindex cbbf1d8a873..bdb61989bf9 100644--- a/spec/models/translation_override_spec.rb+++ b/spec/models/translation_override_spec.rb@@ -7,6 +7,7 @@ describe TranslationOverride dodescribe '#value' dobefore doI18n.backend.store_translations(I18n.locale, some_key: '%{first} %{second}')+ I18n.backend.store_translations(:en, something: { one: '%{key1} %{key2}', other: '%{key3} %{key4}' })enddescribe 'when interpolation keys are missing' do@@ -36,6 +37,40 @@ describe TranslationOverride doendendend++ describe 'pluralized keys' do+ describe 'valid keys' do+ it 'converts zero to other' do+ translation_override = TranslationOverride.upsert!(I18n.locale, 'something.zero', '%{key3} %{key4} hello')+ expect(translation_override.errors.full_messages).to eq([])+ end++ it 'converts two to other' do+ translation_override = TranslationOverride.upsert!(I18n.locale, 'something.two', '%{key3} %{key4} hello')+ expect(translation_override.errors.full_messages).to eq([])+ end++ it 'converts few to other' do+ translation_override = TranslationOverride.upsert!(I18n.locale, 'something.few', '%{key3} %{key4} hello')+ expect(translation_override.errors.full_messages).to eq([])+ end++ it 'converts many to other' do+ translation_override = TranslationOverride.upsert!(I18n.locale, 'something.many', '%{key3} %{key4} hello')+ expect(translation_override.errors.full_messages).to eq([])+ end+ end++ describe 'invalid keys' do+ it "does not transform 'tonz'" do+ translation_override = TranslationOverride.upsert!(I18n.locale, 'something.tonz', '%{key3} %{key4} hello')+ expect(translation_override.errors.full_messages).to include(I18n.t(+ 'activerecord.errors.models.translation_overrides.attributes.value.invalid_interpolation_keys',+ keys: 'key3, key4'+ ))+ end+ end+ endendend