Add translations for moderation ajax controller

This commit is contained in:
Andreas Nedbal 2022-07-06 11:06:23 +02:00 committed by Karina Kwiatek
parent e6e7780142
commit 2237ff8f04
3 changed files with 45 additions and 44 deletions

View File

@ -14,13 +14,13 @@ class Ajax::ModerationController < AjaxController
rescue => e
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = I18n.t('messages.moderation.vote.fail')
@response[:message] = t(".error")
return
end
@response[:count] = report.votes
@response[:status] = :okay
@response[:message] = I18n.t('messages.moderation.vote.okay')
@response[:message] = t(".success")
@response[:success] = true
end
@ -34,13 +34,13 @@ class Ajax::ModerationController < AjaxController
rescue => e
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = I18n.t('messages.moderation.destroy_vote.fail')
@response[:message] = t(".error")
return
end
@response[:count] = report.votes
@response[:status] = :okay
@response[:message] = I18n.t('messages.moderation.destroy_vote.okay')
@response[:message] = t(".success")
@response[:success] = true
end
@ -55,12 +55,12 @@ class Ajax::ModerationController < AjaxController
rescue => e
Sentry.capture_exception(e)
@response[:status] = :fail
@response[:message] = I18n.t('messages.moderation.destroy_report.fail')
@response[:message] = t(".error")
return
end
@response[:status] = :okay
@response[:message] = I18n.t('messages.moderation.destroy_report.okay')
@response[:message] = t(".success")
@response[:success] = true
end
@ -76,12 +76,12 @@ class Ajax::ModerationController < AjaxController
rescue ActiveRecord::RecordInvalid => e
Sentry.capture_exception(e)
@response[:status] = :rec_inv
@response[:message] = I18n.t('messages.moderation.create_comment.rec_inv')
@response[:message] = t(".invalid")
return
end
@response[:status] = :okay
@response[:message] = I18n.t('messages.moderation.create_comment.okay')
@response[:message] = t(".success")
@response[:success] = true
@response[:render] = render_to_string(partial: 'moderation/discussion', locals: { report: report })
@response[:count] = report.moderation_comments.all.count
@ -95,20 +95,20 @@ class Ajax::ModerationController < AjaxController
unless current_user == comment.user
@response[:status] = :nopriv
@response[:message] = I18n.t('messages.moderation.destroy_comment.nopriv')
@response[:message] = t(".nopriv")
return
end
comment.destroy
@response[:status] = :okay
@response[:message] = I18n.t('messages.moderation.destroy_comment.okay')
@response[:message] = t(".success")
@response[:success] = true
end
def ban
@response[:status] = :err
@response[:message] = I18n.t('messages.moderation.ban.error')
@response[:message] = t(".error")
params.require :user
params.require :ban
@ -122,18 +122,18 @@ class Ajax::ModerationController < AjaxController
if !unban && target_user.has_role?(:administrator)
@response[:status] = :nopriv
@response[:message] = I18n.t('messages.moderation.ban.nopriv')
@response[:message] = t(".nopriv")
return
end
if unban
UseCase::User::Unban.call(target_user.id)
@response[:message] = I18n.t('messages.moderation.ban.unban')
@response[:message] = t(".success.unban")
@response[:success] = true
@response[:status] = :okay
return
elsif perma
@response[:message] = I18n.t('messages.moderation.ban.perma')
@response[:message] = t(".success.permanent")
expiry = nil
else
params.require :duration
@ -142,7 +142,7 @@ class Ajax::ModerationController < AjaxController
raise Errors::InvalidBanDuration unless %w[hours days weeks months].include? duration_unit
expiry = DateTime.now + duration.public_send(duration_unit)
@response[:message] = I18n.t('messages.moderation.ban.temp', date: expiry.to_s)
@response[:message] = I18n.t(".success.temporary", date: expiry.to_s)
end
UseCase::User::Ban.call(
@ -168,12 +168,12 @@ class Ajax::ModerationController < AjaxController
target_user = User.find_by_screen_name!(params[:user])
@response[:message] = I18n.t('messages.moderation.privilege.nope')
@response[:message] = t(".error")
return unless %w(moderator admin).include? params[:type].downcase
unless current_user.has_role?(:administrator)
@response[:status] = :nopriv
@response[:message] = I18n.t('messages.moderation.privilege.nopriv')
@response[:message] = t(".nopriv")
return
end
@ -188,7 +188,7 @@ class Ajax::ModerationController < AjaxController
end
target_user.save!
@response[:message] = I18n.t('messages.moderation.privilege.checked', privilege: params[:type])
@response[:message] = t(".success", privilege: params[:type])
@response[:status] = :okay
@response[:success] = true

View File

@ -42,6 +42,33 @@ en:
success:
add: "Successfully added user to list."
remove: "Successfully removed user from list."
moderation:
vote:
success: "Successfully voted on report."
error: "You have already voted on this report."
destroy_vote:
success: "Successfully removed vote from report."
error: "You have not voted on that report."
destroy_report:
success: "Successfully removed report."
error: :errors.base
create_comment:
invalid: "Your comment is too long."
success: "Comment posted successfully."
destroy_comment:
nopriv: "Can't delete other people's comments."
success: "Successfully deleted comment."
ban:
nopriv: "You cannot ban an administrator!"
success:
unban: "Unbanned user."
permanent: "Permanently banned user."
temporary: "Banned user until %{date}"
error: "Something went wrong while banning this user."
privilege:
nopriv: "You can't change the role of this user."
success: "Successfully adjusted this users %{privilege} role."
error: "Something went wrong while adjusting this role."
mute_rule:
nopriv: "Can't edit other people's rules"
create:

View File

@ -65,32 +65,6 @@ en:
destroy:
nopriv: "can't delete other people's answers"
okay: "Successfully deleted answer."
moderation:
vote:
fail: "You have already voted on this report."
okay: "Successfully voted on report."
destroy_vote:
fail: "You have not voted on that report."
okay: "Successfully removed vote from report."
destroy_report:
fail: "Something bad happened!"
okay: "WHERE DID IT GO??? OH NO!!!"
create_comment:
rec_inv: "Your comment is too long."
okay: "Comment posted successfully."
destroy_comment:
nopriv: "can't delete other people's comments"
okay: "Successfully deleted comment."
ban:
error: "Weird..."
nopriv: "You cannot ban an administrator!"
unban: "Unbanned user."
perma: "Permanently banned user."
temp: "Banned user until %{date}"
privilege:
nope: "nope!"
nopriv: "You'd better check YOUR privileges first!"
checked: "Successfully checked this user's %{privilege} privilege."
question:
destroy:
not_found: "Question does not exist"