mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 02:52:44 +08:00
Remove validation for invalid interpolation keys.
* Our codebase currently supports custom interpolations keys that are not present in the original translation. The proper fix should be to make `TranslateOverride` aware of such keys.
This commit is contained in:
parent
c5b1317a15
commit
f529cb1674
|
@ -42,7 +42,6 @@ class TranslationOverride < ActiveRecord::Base
|
|||
original_interpolation_keys = I18nInterpolationKeysFinder.find(original_text)
|
||||
new_interpolation_keys = I18nInterpolationKeysFinder.find(value)
|
||||
missing_keys = (original_interpolation_keys - new_interpolation_keys)
|
||||
invalid_keys = (original_interpolation_keys | new_interpolation_keys) - original_interpolation_keys
|
||||
|
||||
if missing_keys.present?
|
||||
self.errors.add(:base, I18n.t(
|
||||
|
@ -52,17 +51,6 @@ class TranslationOverride < ActiveRecord::Base
|
|||
|
||||
return false
|
||||
end
|
||||
|
||||
invalid_keys = (original_interpolation_keys | new_interpolation_keys) - original_interpolation_keys
|
||||
|
||||
if invalid_keys.present?
|
||||
self.errors.add(:base, I18n.t(
|
||||
'activerecord.errors.models.translation_overrides.attributes.value.invalid_interpolation_keys',
|
||||
keys: invalid_keys.join(', ')
|
||||
))
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -413,7 +413,6 @@ en:
|
|||
translation_overrides:
|
||||
attributes:
|
||||
value:
|
||||
invalid_interpolation_keys: 'The following interpolation key(s) are invalid: "%{keys}"'
|
||||
missing_interpolation_keys: 'The following interpolation key(s) are missing: "%{keys}"'
|
||||
|
||||
user_profile:
|
||||
|
|
|
@ -19,19 +19,6 @@ describe TranslationOverride do
|
|||
))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when interpolation keys are invalid' do
|
||||
it 'should not be valid' do
|
||||
translation_override = TranslationOverride.upsert!(
|
||||
I18n.locale, 'some_key', '%{first} %{second} %{third}'
|
||||
)
|
||||
|
||||
expect(translation_override.errors.full_messages).to include(I18n.t(
|
||||
'activerecord.errors.models.translation_overrides.attributes.value.invalid_interpolation_keys',
|
||||
keys: 'third'
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user