diff --git a/lib/jsonapi/exceptions.rb b/lib/jsonapi/exceptions.rb index e917118c..9055c546 100644 --- a/lib/jsonapi/exceptions.rb +++ b/lib/jsonapi/exceptions.rb @@ -402,7 +402,7 @@ def errors status: :bad_request, title: I18n.translate('jsonapi-resources.exceptions.parameter_not_allowed.title', default: 'Param not allowed'), - detail: I18n.translate('jsonapi-resources.exceptions.parameters_not_allowed.detail', + detail: I18n.translate('jsonapi-resources.exceptions.parameter_not_allowed.detail', default: "#{param} is not allowed.", param: param))] end end diff --git a/test/unit/exceptions/translation_test.rb b/test/unit/exceptions/translation_test.rb new file mode 100644 index 00000000..32ff03ab --- /dev/null +++ b/test/unit/exceptions/translation_test.rb @@ -0,0 +1,34 @@ +require File.expand_path('../../../test_helper', __FILE__) + +class TranslationTest < ActiveSupport::TestCase + setup do + @original_locale = I18n.locale + end + + teardown do + I18n.locale = @original_locale + end + + test "parameter_not_allowed translation is loaded correctly in another language" do + I18n.with_locale(:pt) do + I18n.backend.store_translations(:pt, { + "jsonapi-resources": { + exceptions: { + parameter_not_allowed: { + title: "Parâmetro não permitido", + detail: "%{param} não permitido." + } + } + } + }) + + param = "sort" + exception = JSONAPI::Exceptions::ParameterNotAllowed.new(param).errors[0] + expected_title = I18n.t("jsonapi-resources.exceptions.parameter_not_allowed.title") + expected_detail = I18n.t("jsonapi-resources.exceptions.parameter_not_allowed.detail", param: param) + + assert_equal expected_title, exception.title + assert_equal expected_detail, exception.detail + end + end +end \ No newline at end of file