API: Publish translations

Last updated: September 11, 2024Author: 

This endpoint allows you to publish translations in the translation editor to the translation hosting or to publish them from one hosting environment to another. You can see your project environments in 'Hosting' tab of your project. Please note that this endpoint requires authorization and it's only available for paid plans.

Publish translations

POST
https://api.simplelocalize.io
/api/v2/environments/{environmentKey}/publish

Description

A request to this endpoint may require some time to complete. Please do not send another request until the previous one is completed, otherwise endpoint will return error response. Please try to avoid sending too many requests in a short period of time, otherwise rate-limiter service may block your next requests a while. Our recommendation is to send a request to this endpoint only when you are ready to publish translations and not more often than once per minute.

Publish translations from Translation Editor

To publish translations from translation editor, you need to specify _latest environment in environment query parameter.

curl
    --location
    --request POST 'https://api.simplelocalize.io/api/v2/environments/_latest/publish' \
    --header 'X-SimpleLocalize-Token: <API_KEY>' \
    --header 'Content-Type: application/json'

Publish translations to the production environment

To publish translations to production environment, you need to specify _production environment in environment query parameter. Translations will be taken from the _latest environment by default.

curl
    --location
    --request POST 'https://api.simplelocalize.io/api/v2/environments/_production/publish' \
    --header 'X-SimpleLocalize-Token: <API_KEY>' \
    --header 'Content-Type: application/json'

Publish translations to the custom environment

To publish translations to the custom environment, you need to specify your custom environment key in environment query parameter. The source environment is always taken from the configured order (from top to bottom) in the project settings page.

You can change the order of hosting environments in the 'Settings' -> 'Hosting' tab.

Translation Hosting order of hosting environments

The environment key can be found in the 'Settings' -> 'Hosting' tab. The key has been set during the environment creation, and it cannot be changed after creation.

Translation Hosting environment key

Sample request

According to the above example, the environment key is staging, and the source environment is _production.

curl
    --location
    --request POST 'https://api.simplelocalize.io/api/v2/environments/staging/publish' \
    --header 'X-SimpleLocalize-Token: <API_KEY>' \
    --header 'Content-Type: application/json'

Get environment status

GET
https://api.simplelocalize.io
/api/v2/environments/{environmentKey}

Description

This endpoint allows you to check the current status of the environment, with the number of keys, languages, and non-empty translations and list of resources to download or use in your application.

Sample request

curl -X 'GET' \
  'https://api.simplelocalize.io/api/v2/environments/{environmentKey}' \
  -H 'accept: application/json' \
  -H 'X-SimpleLocalize-Token: <API_KEY>'

The response will look like this:

{
  "msg": "OK",
  "status": 200,
  "data": {
    "numberOfKeys": 81,
    "numberOfLanguages": 6,
    "numberOfNonEmptyTranslations": 471,
    "createdAt": "2023-10-05T12:55:20.987Z",
    "resources": [
      {
        "link": "752a12896c194846aac2bac83efc6c79/_latest/_index",
        "size": 9333
      },
      {
        "link": "752a12896c194846aac2bac83efc6c79/_latest/pl_PL/login",
        "language": "pl_PL",
        "namespace": "login",
        "size": 385
      }
    // cut for brevity...
    ]
  }
}
FieldDescription
numberOfKeysThe number of keys in the environment.
numberOfLanguagesThe number of languages in the environment.
numberOfNonEmptyTranslationsThe number of non-empty translations in the environment.
createdAtThe date when the environment was published.
resourcesThe list of resources in the environment.
resources.linkThe path to the resource
resources.sizeThe size of the resource in bytes
resources.languageThe language of the resource (if applies)
resources.namespaceThe namespace of the resource (if applies)
resources.customerThe customer of the resource (if applies)

The link field is a path to the resource. By default, you should append the https://cdn.simplelocalize.io/ prefix to the link to get the full URL to the resource.

Was this helpful?