From 73ac74233289096028cd2caae6673873e5956d9d Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Wed, 6 Jul 2022 13:13:17 +0200 Subject: [PATCH] Add translations for ajax controller error handling --- app/controllers/ajax_controller.rb | 10 +++++----- config/locales/controllers.en.yml | 17 +++++++++-------- config/locales/en.yml | 3 --- config/locales/errors.en.yml | 6 ++++++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/controllers/ajax_controller.rb b/app/controllers/ajax_controller.rb index 114d02a4..c9732555 100644 --- a/app/controllers/ajax_controller.rb +++ b/app/controllers/ajax_controller.rb @@ -12,7 +12,7 @@ class AjaxController < ApplicationController @response = { success: false, - message: "Something went wrong", + message: t("errors.base"), status: :err } @@ -25,7 +25,7 @@ class AjaxController < ApplicationController @response = { success: false, - message: "Missing parameter: #{e.key}", + message: t("errors.parameter_error", parameter: e.key), status: :err } @@ -37,7 +37,7 @@ class AjaxController < ApplicationController @response = { success: false, - message: "Invalid parameter", + message: t("errors.invalid_parameter"), status: :err } @@ -49,7 +49,7 @@ class AjaxController < ApplicationController @response = { success: false, - message: "Record not found", + message: t("errors.record_not_found"), status: :not_found } @@ -61,7 +61,7 @@ class AjaxController < ApplicationController @response = { success: false, - message: I18n.t("messages.parameter_error", parameter: e.param.capitalize), + message: t("errors.parameter_error", parameter: e.param.capitalize), status: :parameter_error } diff --git a/config/locales/controllers.en.yml b/config/locales/controllers.en.yml index 841a40ad..f1793c2f 100644 --- a/config/locales/controllers.en.yml +++ b/config/locales/controllers.en.yml @@ -1,5 +1,6 @@ en: ajax: + noauth: "You need to be logged in to perform this action." anonymous_block: create: success: :ajax.relationship.create.block.success @@ -23,7 +24,7 @@ en: success: "Successfully deleted comment." inbox: create: - noauth: :messages.noauth + noauth: :ajax.noauth success: "Successfully added new question." remove: success: "Successfully deleted question." @@ -34,18 +35,18 @@ en: success: :ajax.inbox.remove_all.success list: create: - noauth: :messages.noauth + noauth: :ajax.noauth noname: "Please give that list a name." toolong: "List name too long (30 characters max.)" notfound: "Could not find user." exists: "List already exists." success: "Successfully created list." destroy: - noauth: :messages.noauth + noauth: :ajax.noauth notfound: "Could not find list." success: "Successfully deleted list." membership: - noauth: :messages.noauth + noauth: :ajax.noauth notfound: "List not found." success: add: "Successfully added user to list." @@ -80,14 +81,14 @@ en: mute_rule: nopriv: "Can't edit other people's rules" create: - noauth: :messages.noauth + noauth: :ajax.noauth success: "Rule added successfully." update: - noauth: :messages.noauth + noauth: :ajax.noauth nopriv: :ajax.mute_rule.nopriv success: "Rule updated successfully." destroy: - noauth: :messages.noauth + noauth: :ajax.noauth nopriv: :ajax.mute_rule.nopriv success: "Rule deleted successfully." question: @@ -116,7 +117,7 @@ en: error: "You are not following that user." report: create: - noauth: :messages.noauth + noauth: :ajax.noauth unknown: "You can't report this entity." notfound: "Could not find %{parameter}" success: "%{parameter} reported. A moderator will decide what happens with the %{parameter}." diff --git a/config/locales/en.yml b/config/locales/en.yml index c2b0a8d2..706246df 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -53,9 +53,6 @@ en: until: "Banned until: %{time}" messages: noscript: "Please activate JavaScript." - error: "An error occurred." - parameter_error: "%{parameter} is required." - noauth: "requires authentication" views: locale: languages: "Languages" diff --git a/config/locales/errors.en.yml b/config/locales/errors.en.yml index 8a0e8aab..90e4a2d1 100644 --- a/config/locales/errors.en.yml +++ b/config/locales/errors.en.yml @@ -27,3 +27,9 @@ en: conflict: "This already exists" invalid_otp: "The code you entered was invalid." + + parameter_error: "%{parameter} is required." + + invalid_parameter: "Invalid parameter" + + record_not_found: "Record not found"