Skip to content

i18n

Internationalization

  • Internationalization is used to get your error or response messages in multiple languages from the API Maker.
  • While you need to get a response or error message in any language, you have to provide the x-am-internationalization value in the request header.
  • E.g. If we have two internationalization added with the name 'HINDI' & 'ENGLISH', and the user provides x-am-internationalization: 'HINDI' the response message or error message will be in the given language. Just you have to map that error/response messages.

Here, we can map - Constant errors - Custom API errors - Third party API errors - Predefined messages templates

Constant errors

  • These are the pre-defined error list.
  • Key: value pairs. You can update the values as per you're convenient. You will get that error value in your error response.

Example: - Let update the constant error like this "Please provide name.": "Please provide valid name." and save that i18n with name 'my_custom'. - While send the request, you have to provide the '_id' of the 'my_custom' i18n in the header x-am-internationalization. - Now call the custom API with the below code.

throw "Please provide name.";

Response

{
    "success": false,
    "statusCode": 500,
    "errors": [
        {
            "code": 500,
            "message": "Please provide valid name."
        }
    ],
    "warnings": []
}

Custom API errors

  • Add 'key:value' pairs for your custom API errors in your i18n.
  • Provide '_id' of that i18n in the request header as x-am-internationalization.

Example:

  • Let, we set "Test custom API errors.": "Unable to process this request!" in the i18n.
  • While send the request, you have to provide the '_id' of the i18n in the header x-am-internationalization.

From the custom API throw error as shown below.

throw "Test custom API errors";

Response

{
    "success": false,
    "statusCode": 500,
    "errors": [
        {
            "code": 500,
            "message": "Unable to process this request!"
        }
    ],
    "warnings": []
}

Third party API errors

  • Add 'key:value' pairs for your third party API errors in your i18n.
  • Provide '_id' of that i18n in the request header as x-am-internationalization.

Example:

  • Let, we set "Test the ErrorList feature in TP APIs.": "Test the ErrorList feature in TP APIs." in the i18n.
  • While send the request, you have to provide the '_id' of the i18n in the header x-am-internationalization.

From the custom API throw error as shown below.

throw "Test the ErrorList feature in TP APIs.";

Response

{
    "success": false,
    "statusCode": 500,
    "errors": [
        {
            "code": 500,
            "message": "Test the ErrorList feature in TP APIs.!"
        }
    ],
    "warnings": []
}