Read API

Integrate

Read API

Pull translations into your app, with copy-paste code in eight languages.

On this page

Lantern is the source of truth for your translations. Your app keeps its locale files — locales/en.json, locales/fr.json and so on — in sync by pulling them from the read API, usually as a step in your build or deploy.

  • Base URL: https://lantern.abyss-inn.ch
  • Auth: an API token from the project’s API tab, sent as a Bearer header.

The endpoint#

GET /api/v1/projects/<slug>/translations
Authorization: Bearer lk_…
Query parameterValuesMeaning
formatjson (default), csv, androidOutput format
localeA locale code, like enOne language. Leave it out for all languages.
nested1Nested JSON instead of flat, dotted keys
pluralsi18nextPlurals as i18next keys (key_one, key_other…) instead of one ICU value. JSON only.

Responses#

?locale=en&nested=1 returns one language:

{ "home": { "title": "Welcome" } }

Without locale, ?nested=1 returns every language, keyed by locale — the best fit for syncing files:

{ "en": { "home": { "title": "Welcome" } }, "fr": { "home": { "title": "Bienvenue" } } }

format=csv returns a key column plus one column per locale.

format=android&locale=fr returns one language as an Android strings.xml. With this format, locale is required.

Errors#

StatusMeaning
401Missing or invalid token
403The token doesn’t belong to this project
400Unknown locale or bad format
404Project not found

Listing languages#

The translations call only exposes locale codes. To list a project’s languages with their display names, call:

GET /api/v1/projects/<slug>/languages
Authorization: Bearer lk_…
→ 200 [ { "locale": "en", "name": "English", "isDefault": true }, … ]

Code samples#

Each sample fetches every locale in one request (?nested=1) and writes one locales/<locale>.json per language. To pull a single language, add ?locale=en and write one file.

Set LANTERN_TOKEN in your environment and replace my-project with your project’s slug. For a ready-made script, see the CLI.

#!/usr/bin/env bash
set -euo pipefail
: "${LANTERN_TOKEN:?set LANTERN_TOKEN}"
BASE=https://lantern.abyss-inn.ch ; SLUG=my-project ; OUT=locales
mkdir -p "$OUT"
curl -fsS -H "Authorization: Bearer $LANTERN_TOKEN" \
  "$BASE/api/v1/projects/$SLUG/translations?nested=1" \
| jq -c 'to_entries[]' | while read -r e; do
    loc=$(jq -r '.key' <<<"$e")
    jq '.value' <<<"$e" > "$OUT/$loc.json"
    echo "wrote $OUT/$loc.json"
  done

When to pull#

  1. Pull at build time (recommended). Run a pull step before your build, so the files you ship are always current. Whether you commit the generated locales/ folder or ignore it in git is up to you.
  2. Fetch at runtime and cache. Long-running servers can fetch on start and refresh on an interval. Keep the result in memory, and fall back to the last good copy on an error.
  3. On a schedule. For apps that run without redeploying, run the pull on a timer and reload.

Using the files in an i18n library#

The nested JSON matches what most i18n libraries expect:

  • JavaScript / TypeScript: i18next (resources), react-intl, vue-i18n, next-intl
  • Python: load the JSON and look up by dotted key, or use the flat output
  • C#: bind it to IStringLocalizer JSON sources, or read the files directly
  • Rust: fluent or rust-i18n; the flat output may suit them better