🌐Localization (i18n)
1. Get module in Postman collection
2. Getting a list of available languages
To get a list of available languages, use the "Get languages" request. An example response would look like this:
{
"notification": null,
"warning": null,
"variables": null,
"internalStatus": "000000",
"response": [
{
"code": "en",
"title": "English"
},
{
"code": "ua",
"title": "Українська"
}
],
"errors": null
}
3. Getting a list of translations
The list consists of key-value pairs. To get a list in the specific language (default English), you need to pass the x-language header, the value of which will contain the locale from the first request (code attribute):
curl --location --globoff --request GET '{{APP_URL}}/simulator/api/v1/localization' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-api-key: {{API_KEY}}' \
--header 'x-language: ua'
As a result, you will get a list of localizations:
{
"notification": null,
"warning": null,
"variables": null,
"internalStatus": "000000",
"response": {
"validation": {
"required": "This field is required",
"minLength": "Minimum length is {minPasswordlength} characters",
"email": "Please enter a valid email address"
},
"button": {
"submit": "Submit",
"cancel": "Cancel"
},
"termsOfUse": {
"title": "Terms of Use",
"content": "By accessing or using the website {websiteName}, you agree to be bound by our Terms of Use."
}
},
"errors": null
}
4. Working with variables
If you pay attention to the response above, there are variables in the localization text: {minPasswordLength}
, {websiteName}
.
Sometimes the client needs to display more information than static text. For example, when a user get an error during registration, there may be a message - The minimum password length is {minPasswordLength}
.
In this case, you will get values in “variables” attribute:
{
"notification": null,
"warning": null,
"variables": {
"minPasswordLength": 8
},
"internalStatus": "000000",
"response": null,
"errors": {
"password": [
"validation.minLength"
]
}
}
If you find a value in translation text that has a {<someText>}
pattern, you will need to find the key in the “variables” attribute. After that, replace {<someText>}
with the value of the variable.
Minimum length is {minPasswordLength}
characters → Minimum length is 8 characters
Last updated