transglot
v0.5.1
Published
Set up transglot from your terminal: browser sign-in, repository scan and first translation, then push and pull in CI.
Maintainers
Readme
transglot
Localize a repository from your terminal. transglot init finds your locale files, signs you in
through the browser, runs the first translation and writes the files back. In CI the same CLI
pushes source strings and pulls translations with a project token. It has no runtime
dependencies.
Requirements
Node.js 22 or later, and a browser to approve the sign-in, on this machine or on any other.
Set up a repository
npx transglot@latest initRun it as npx transglot@latest: in a repository that lists an older transglot as a development
dependency, npx without @latest runs that older version.
init reads your locale files and works out the source language before anything leaves the
machine. Then it prints a link and a code and opens your browser. There you sign in or sign up,
check that the page shows the same code, and approve. The page then picks the workspace and the
project, or creates the project init proposed from your files, and offers a trial when the
workspace's plan does not include API access yet. Back in the terminal, init writes
transglot.json, uploads your source strings and the translations you already have, shows how
many words the first translation needs, asks once, runs it with a progress bar per language, and
writes the translated files.
Connecting creates a project token, so the login that approves needs to be an admin of the workspace or above. A developer is told which admins can connect it instead.
Outside an interactive terminal (a script, an agent, CI) init asks nothing and takes every
choice from flags; --yes accepts the defaults in a terminal too. transglot --help lists
every flag.
Commands
| Command | What it does |
| --- | --- |
| transglot init | Sets this repository up, as above. When transglot.json already exists and this machine has no token for it, it links this folder to that project and uploads nothing. |
| transglot push | Uploads source strings per sources in transglot.json. |
| transglot pull | Downloads translations per pull in transglot.json. |
| transglot status | Shows the project and its active runs, or one run. |
| transglot cancel | Stops a running translation. It always needs TRANSGLOT_TOKEN. |
Where the token is kept
The browser shows a code such as WDJB-MJHT. Approve only a code you started yourself. When the
browser and the terminal reach Transglot from different networks (SSH, a container, a VPN that
covers only the browser), the page also shows a two-digit number to type into the terminal, or
to pass as transglot init --confirm <number>.
Approving creates an ordinary project token that can push and pull, named after this machine. It
is listed with the project's other tokens in the console, where it can be revoked. init keeps
it in credentials.json, in the first of these folders that applies:
TRANSGLOT_CONFIG_DIR, when it is set;$XDG_CONFIG_HOME/transglot, whenXDG_CONFIG_HOMEis an absolute path;%LOCALAPPDATA%\transgloton Windows;~/.config/transglototherwise.
On macOS and Linux only your user can read it: the file is 0600 in a 0700 folder. On Windows
it is protected by the permissions of your local profile folder. A token is only ever sent to the
server it was created on.
init also writes .transglot/project.json into the repository and adds .transglot/ to
.gitignore. It names the token for this machine only, so a copy of the folder on another
machine, or a committed copy, selects nothing. In that folder push, pull and status use
the stored token.
In CI
Create a deploy token for the project in the console and store it as the TRANSGLOT_TOKEN
secret. When it is set it always wins: push, pull, status, cancel and init use it
and never read this machine's stored token or open a browser. Browser sign-in does not run in CI.
npx --yes transglot@latest push --wait
npx --yes transglot@latest pullEnvironment variables
| Variable | What it does |
| --- | --- |
| TRANSGLOT_TOKEN | A project token. When it is set, commands use it instead of the token stored for this folder. |
| TRANSGLOT_URL | The server, when it is not https://api.transglot.ai. It overrides url in transglot.json. |
| TRANSGLOT_APP_URL | The web address sign-in links must point to, for a server whose app is not on the same parent domain. |
| TRANSGLOT_CONFIG_DIR | The folder that holds credentials.json. |
| TRANSGLOT_BROWSER | none never opens a browser; any other value is the command that opens the link. The link is printed either way. |
| TRANSGLOT_INTERACTIVE | 0 never asks a question; 1 asks even where the CLI would otherwise assume an automated environment. |
Exit codes
| Code | Meaning |
| --- | --- |
| 0 | Success. |
| 1 | Configuration, or a choice that needs a flag outside an interactive terminal. |
| 2 | Sign-in, token or access refused. The message says what to change. |
| 3 | The run would exceed the workspace's word limit. |
| 4 | A translation run failed or was stopped. |
| 5 | Timed out while waiting. |
| 6 | Server or network error. |
| 130 | Interrupted with Ctrl+C during the browser sign-in. |
Scripts can rely on these codes, and on the lines push and pull print for them:
Batch: #<id>, written <path> and unchanged <path>.
What pull will not overwrite
If the server reports zero entries for a locale, pull refuses to write over an existing
non-empty file and exits 1 with refusing to overwrite <path> with an empty bundle. That happens
for ordinary reasons: the locale has not been translated yet, min_state: reviewed matches
nothing so far, or a push is still running (it returns as soon as the run is queued, so use
transglot push --wait && transglot pull rather than the bare pair).
Writing to a path that does not exist yet is unaffected, so a first pull still creates the
file. If you really are clearing a locale, pass --allow-empty.
The pull that ends init is stricter. It writes a file only when the server can be shown to hold
what is in it. Any other file is kept, and init says which and why, since transglot pull
would replace it with the server's copy. In a terminal it asks before replacing such a file.
A pulled file is sparse, and next-intl does not fill the gaps
A pulled locale file holds what the project has for that locale, not one entry
per key. A key nobody has translated yet is absent. So is a key filtered out by
min_state. And on a project whose message syntax is set to icu, so is a key
whose translation is not valid ICU MessageFormat, because handing that string to
a formatter is a crash at render time rather than a wrong word on the page. The
response headers carry the numbers: X-Skipped-Keys for entries the format
cannot represent, X-Omitted-Invalid-Icu-Keys and X-Omitted-Invalid-Icu-Sample
for entries the ICU gate withheld.
pull (0.5.0 and later) prints the ICU gate's omissions under the file they
concern, with the first names the server sent:
written messages/fr.json
omitted 3 invalid ICU translation(s) for fr: cart.items, cart.total, and 1 moreFix those translations in transglot and the next pull writes them.
next-intl does not fall back to another locale by itself. Reading a key that
is not in the active locale's messages raises MISSING_MESSAGE, and the string
that renders is the key's own dotted path, so cart.items renders as
cart.items. In development that also logs an error.
Merge the source locale underneath the target locale yourself, in
i18n/request.ts, so a key that is absent renders the source string:
import { getRequestConfig } from 'next-intl/server';
type Messages = { [key: string]: string | Messages };
type Merge = (base: Messages, override: Messages) => Messages;
// Deep, because messages nest: a shallow spread would replace the whole `cart`
// object with the French one and lose every English key inside it. The types sit
// on the `Merge` alias rather than on the parameters so the body stays plain
// JavaScript, which is also what lets our own test run this exact snippet.
const deepMerge: Merge = function deepMerge(base, override) {
const out = { ...base };
for (const [key, right] of Object.entries(override)) {
const left = out[key];
out[key] =
typeof left === 'object' && typeof right === 'object'
? deepMerge(left, right)
: right;
}
return out;
};
export default getRequestConfig(async ({ requestLocale }) => {
const locale = (await requestLocale) ?? 'en';
const source = (await import('../messages/en.json')).default;
const target = (await import(`../messages/${locale}.json`)).default;
return { locale, messages: deepMerge(source, target) };
});Pull the source locale into messages/en.json alongside the target locales for
this to have something to fall back to. What the reader sees for an absent key is
then the English string rather than cart.items, and a translation the ICU gate
withheld renders as English rather than throwing.
Key metadata sidecars
A key's description is the context the AI translator and your reviewers read, and
its max_length is the ceiling a translation is checked against. Formats such as
json_flat, json_nested, android_xml or ios_strings have nowhere to keep
either, so a sources rule can name a sidecar that states them (0.5.0 and later):
{
"sources": [
{
"path": "messages/{locale}.json",
"format": "json_nested",
"metadata": "i18n/en.meta.json"
}
]
}{
"cart.title": { "description": "Heading of the cart page", "max_length": 40 },
"cart.items": { "description": "Item count under the cart heading" },
"legacy.banner": { "description": null }
}- Keys are the project's key names, dotted as the project stores them.
- A field that is absent is left alone;
nullclears it.max_lengthis a whole number from 1 to 100000,descriptionat most 2,000 characters. - At most 1 MiB and 50,000 keys. A key named twice is refused.
push reads and checks the sidecar before it uploads anything, so a bad one stops
the run with nothing sent, and a syntax error is reported as file:line:col
without quoting the file. The sidecar rides the rule's upload for the project's
source locale, and that upload goes after the rest of that locale's files, so keys
a sibling file creates exist by the time their descriptions arrive. push then
prints what changed:
push messages/en.json (en, json_nested)
keys_created 0
...
descriptions_updated 2
max_lengths_updated 1
metadata for unknown keys (1), not applied:
- legacy.bannerA server that predates sidecars ignores the file, and push says so:
warning: this server ignored the metadata sidecar.
Refused, with a config error: metadata on a pull rule; a path with a {…}
token (a rule has exactly one sidecar); a rule whose locales include no upload, or
more than one upload, for the source locale; a path that leaves the working
directory, including through a symlink; and a format that carries descriptions in
the file itself, whose descriptions push already reads: flutter_arb, xliff_12,
ios_xcstrings, gettext_po, csv, xlsx, unity_csv and unreal_po.
File formats
Every rule in sources and pull carries a format. transglot init detects it
from your files; name one with --format, together with --path, when it cannot.
| Format | Default extension |
| --- | --- |
| json_flat | .json |
| json_nested | .json |
| android_xml | .xml |
| ios_strings | .strings |
| ios_stringsdict | .stringsdict |
| flutter_arb | .arb |
| laravel_php | .php |
| laravel_json | .json |
| xliff_12 | .xlf |
| ios_xcstrings | .xcstrings |
| gettext_po | .po |
| yaml | .yml |
| csv | .csv |
| xlsx | .xlsx |
| xliff_20 | .xlf |
| java_properties | .properties |
| resx | .resx |
| markdown | .md |
| unity_csv | .csv |
| unreal_po | .po |
unity_csv and unreal_po are the game engine formats (Unity string tables and
Unreal .po catalogs).
This table is pinned by tests/format-parity.test.ts, which reads the server's
app/Enums/FileFormat.php and fails if the CLI, the table, and the server enum
ever disagree.
