Loco Developer API
Our API makes localizing your software with Loco even more powerful.
Our API makes localizing your software with Loco even more powerful.
The main thing you'll want to do with the Loco API is pull down translation files for whatever you're building. Check out the Export API methods and the export example below.
If you regularly upload translation files into your dashboard, you might want to automate that process. Check out the Import API methods and the import example below.
To automate your Loco workflow further, the API allows you to programmatically manage assets, locales, tags and translations.
Get going with the quick start guide or browse the available methods in our API reference.
The original API explorer is deprecated, but is available here for the foreseeable future.
We recommend using the new API reference if possible. Future API versions won't be compatible with the old interface, because it's based on the out-dated Swagger 1.2 specification.
The latest version of the Loco API is discoverable here in OpenAPI format. This spec will be updated for future API versions.
Version 1.0.29 is discoverable here in the out-dated Swagger 1.2 format. This spec won't be updated.
Here are some workflow examples. We've started a new project, so we'll add some assets and locales and make some translations. These examples use command line cURL. Responses in green are simplified.
The most common starting point for using Loco is to get an existing batch of source strings into your dashboard. This example imports a Gettext POT file into a fresh project which needs only to contain our default language for now.
$ curl --data-binary @messages.pot 'https://localise.biz/api/import/pot' -u <your_key>:
HTTP/1.1 200 Ok
{ "message": "100 translations imported, 100 new assets" ... }
This is the quickest way to get started, but the API provides more fine-grained control than simply importing and exporting whole files. See below for some more specific actions you could automate.
Most operations in Loco revolve around assets. Importing them from an existing file is the quickest route, but the API also lets you add them individually. Here we post the string "Hello World" to the assets collection to create a new translatable item.
$ curl -F'id=hello' -F'text=Hello World' 'https://localise.biz/api/assets' -u <your_key>:
HTTP/1.1 201 Created
...
{ "id":"hello", "type":"text", "progress":{"translated":1 ... }
progress field shows that one translation exists.id=hello a unique ID would have been automatically generated. You'll need this to reference the asset later.Our project is only in English at the moment, so here we add Spanish by posting to the locales collection.
$ curl -F 'code=es' 'https://localise.biz/api/locales' -u <your_key>:
HTTP/1.1 201 Created
...
{ "code":"es", "name":"Spanish", "plurals": { "length":2, "equation":"n != 1", "forms":["one","other"] } ... }
Now that we have an asset to translate and something to translate it into, we can create our first translation. Here we post the translated text to the translation endpoint. Note that the translation is posted as the raw request body.
$ curl --data-binary 'Hola Mundo' 'https://localise.biz/api/translations/hello/es' -u <your_key>:
...
{ "id":"hello", "translated":true, "translation":"Hola Mundo", "revision":1, ... }
Finally we want to export all our translations to the file format we're using in our software. Here we use the Export API to pull our Spanish translations into a Gettext PO file. See the full list of export formats.
$ curl 'https://localise.biz/api/export/locale/es.po' -u <your_key>:
...
msgid "Hello World"
msgstr "Hola Mundo"
You'll notice that the PO file hasn't used our unique "hello" ID.
This is the nature of PO files - the source text is used instead of a language-agnostic key.
Compare that with what an Android XML file would look like for our English translations:
$ curl 'https://localise.biz/api/export/locale/en.xml?format=android' -u <your_key>:
...
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="hello">Hello World</string>
</resources>
Loco can work with or without language-agnostic keys. The import and export APIs provide you full control over this, so you can manage the same set of translations over multiple platforms.