{
"errors": [
{
"message": "Argument 'facultativeMark' on InputObject 'FacultativeMarkAttributes' is required. Expected type Int!",
"locations": [
{
"line": 2,
"column": 52
}
],
"path": [
"mutation addfacultativMark",
"addFacultativeMark",
"attributes",
"facultativeMark"
],
"extensions": {
"code": "missingRequiredInputObjectAttribute",
"argumentName": "facultativeMark",
"argumentType": "Int!",
"inputObjectType": "FacultativeMarkAttributes"
}
}
]
}
require "json"
require "i18n"
errors = JSON.parse(<<~JSON, symbolize_names: true)[:errors]
{
"errors": [
{
"message": "Argument 'facultativeMark' on InputObject 'FacultativeMarkAttributes' is required. Expected type Int!",
"locations": [
{
"line": 2,
"column": 52
}
],
"path": [
"mutation addfacultativMark",
"addFacultativeMark",
"attributes",
"facultativeMark"
],
"extensions": {
"code": "missingRequiredInputObjectAttribute",
"argumentName": "facultativeMark",
"argumentType": "Int!",
"inputObjectType": "FacultativeMarkAttributes"
}
}
]
}
JSON
I18n.available_locales = [:ru]
I18n.locale = :ru
I18n.backend.store_translations(:ru, YAML.load(<<~YAML)["ru"])
ru:
external_api:
errors:
missingRequiredInputObjectAttribute: Аргумент '%{argumentName}' для '%{inputObjectType}' является обязательным. Ожидается тип '%{argumentType}'
YAML
errors.each do |error|
vars = error[:extensions].dup
code = vars.delete(:code)
error[:message_en] = error[:message]
error[:message] = I18n.t(code, scope: "external_api.errors", **vars)
end
pp errors