mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-26 23:41:52 +00:00
Use I18n for media attachment validation errors
These are currently user facing errors, but are not localized. This adds the ability for these messages to be localized.
This commit is contained in:
parent
13c0077003
commit
ad5ddd5e95
|
@ -37,11 +37,11 @@ class PostStatusService < BaseService
|
|||
def validate_media!(media_ids)
|
||||
return if media_ids.nil? || !media_ids.is_a?(Enumerable)
|
||||
|
||||
raise Mastodon::ValidationError, 'Cannot attach more than 4 files' if media_ids.size > 4
|
||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if media_ids.size > 4
|
||||
|
||||
media = MediaAttachment.where(status_id: nil).where(id: media_ids.take(4).map(&:to_i))
|
||||
|
||||
raise Mastodon::ValidationError, 'Cannot attach a video to a toot that already contains images' if media.size > 1 && media.find(&:video?)
|
||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if media.size > 1 && media.find(&:video?)
|
||||
|
||||
media
|
||||
end
|
||||
|
|
|
@ -163,3 +163,7 @@ en:
|
|||
invalid_otp_token: Invalid two-factor code
|
||||
will_paginate:
|
||||
page_gap: "…"
|
||||
media_attachments:
|
||||
validations:
|
||||
too_many: Cannot attach more than 4 files
|
||||
images_and_video: Cannot attach a video to a status that already contains images
|
||||
|
|
|
@ -141,7 +141,7 @@ RSpec.describe PostStatusService do
|
|||
)
|
||||
end.to raise_error(
|
||||
Mastodon::ValidationError,
|
||||
'Cannot attach more than 4 files',
|
||||
I18n.t('media_attachments.validations.too_many'),
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -160,7 +160,7 @@ RSpec.describe PostStatusService do
|
|||
)
|
||||
end.to raise_error(
|
||||
Mastodon::ValidationError,
|
||||
'Cannot attach a video to a toot that already contains images',
|
||||
I18n.t('media_attachments.validations.images_and_video'),
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user