mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 03:06:53 +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:
@ -42,7 +42,6 @@ class TranslationOverride < ActiveRecord::Base
|
|||||||
original_interpolation_keys = I18nInterpolationKeysFinder.find(original_text)
|
original_interpolation_keys = I18nInterpolationKeysFinder.find(original_text)
|
||||||
new_interpolation_keys = I18nInterpolationKeysFinder.find(value)
|
new_interpolation_keys = I18nInterpolationKeysFinder.find(value)
|
||||||
missing_keys = (original_interpolation_keys - new_interpolation_keys)
|
missing_keys = (original_interpolation_keys - new_interpolation_keys)
|
||||||
invalid_keys = (original_interpolation_keys | new_interpolation_keys) - original_interpolation_keys
|
|
||||||
|
|
||||||
if missing_keys.present?
|
if missing_keys.present?
|
||||||
self.errors.add(:base, I18n.t(
|
self.errors.add(:base, I18n.t(
|
||||||
@ -52,17 +51,6 @@ class TranslationOverride < ActiveRecord::Base
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -413,7 +413,6 @@ en:
|
|||||||
translation_overrides:
|
translation_overrides:
|
||||||
attributes:
|
attributes:
|
||||||
value:
|
value:
|
||||||
invalid_interpolation_keys: 'The following interpolation key(s) are invalid: "%{keys}"'
|
|
||||||
missing_interpolation_keys: 'The following interpolation key(s) are missing: "%{keys}"'
|
missing_interpolation_keys: 'The following interpolation key(s) are missing: "%{keys}"'
|
||||||
|
|
||||||
user_profile:
|
user_profile:
|
||||||
|
@ -19,19 +19,6 @@ describe TranslationOverride do
|
|||||||
))
|
))
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user