Web quickstart
Connect a web app that keeps its messages in JSON files. The @airglot/cli tool uploads your source-language messages to AirGlot and writes published translations into the app before the build. It supports next-intl and react-intl (ICU messages) and i18next.
You need an AirGlot app set to JSON (ICU: next-intl, react-intl) or JSON (i18next). Create one under your project with Connect app.
1. Install the CLI
Run it with npx in CI:
npx @airglot/cli pull
Or add it to the project and run npx airglot:
npm install --save-dev @airglot/cli
It needs Node 20 or later.
2. Add airglot.yaml
Put airglot.yaml next to package.json:
app: <your app id>
template: messages/en.json
Your app id is in the app's settings in AirGlot, under Integrations › CI snippet, with template already filled in.
template is the source-language message file, relative to airglot.yaml. Its path must include the source language, such as messages/en.json or locales/en/translation.json. Other languages are written beside it: messages/fr.json or locales/fr/translation.json.
Optional settings:
| Setting | Does |
|---|---|
format | icu or i18next. Guessed from the template when left out. |
descriptions | The file with notes for translators. Defaults to the template's name with .meta.json. |
missing | warn (default) or fail. See Check before you merge. |
When the app is in a subfolder of the repository, pass --project before the command, for example npx @airglot/cli --project web pull.
A folder of message files
When the source language is split over many files, point template at the folder. The folder must be named after the source language. A glob works too:
app: <your app id>
template: src/i18n/messages/en/ # or src/i18n/messages/en/**/*.json
Every .json file in the folder and its subfolders is part of the template. Keys are prefixed with the file's path, so pages/blog/launch.json keeps its own namespace (pages.blog.launch.title). pull writes the same tree for each language beside it.
Notes for translators
JSON has no room for comments, so put notes for translators in a file next to the template, named after it with .meta.json: messages/en.meta.json for messages/en.json. Use the same key paths as the template:
{
"labour": {
"estimate": {
"description": "\"Est.\" is short for \"estimate\": the roster's labour cost.",
"placeholders": { "amount": { "example": "$1,200" } }
}
},
"nav.home": "Link to the dashboard"
}
sync uploads the file with the template when it exists. In a template folder, each file gets its own .meta.json next to it.
3. Create a token and sync
In AirGlot, open the app's settings, then Integrations › CI tokens, and create a token. Store it as the AIRGLOT_TOKEN environment variable, or as a secret in CI. See Tokens.
npx @airglot/cli sync
This uploads the template and its notes file. Run it on every push to your main branch: CI pipelines has ready-made workflows. You can also link the repository on GitHub instead.
Already have translations? Upload them so a reviewer can check them instead of translating from scratch:
npx @airglot/cli import fr
Imported translations wait in Review. Nothing is approved by an import.
4. Check before you merge
npx @airglot/cli check
check catches hand-edited pulled files, lists strings each language file is missing, and checks the template and its notes file against AirGlot's sync rules without saving anything. Set missing: fail in airglot.yaml to fail the build when strings are untranslated, for example in production release jobs.
5. Pull translations into the build
After a release is published in AirGlot, pull it before building:
npx @airglot/cli pull
npx @airglot/cli check
npm run build
pull writes the release's message files beside the template and records them in airglot.lock. Commit airglot.lock so each commit records the release it was built with.
Untranslated strings
Released files leave out strings that aren't translated yet, so your app should show the source text for them.
- i18next does this through
fallbackLng. - next-intl doesn't fall back on its own. Merge the source messages under each language, replacing arrays rather than joining them:
// npm install deepmerge
// i18n/request.ts
import deepmerge from 'deepmerge';
import { getRequestConfig } from 'next-intl/server';
export default getRequestConfig(async ({ requestLocale }) => {
const locale = (await requestLocale) ?? 'en';
const source = (await import('../messages/en.json')).default;
const translated = locale === 'en' ? {} : (await import(`../messages/${locale}.json`)).default;
return {
locale,
messages: deepmerge(source, translated, {
arrayMerge: (_, translatedArray) => translatedArray,
}),
};
});
The app's settings in AirGlot show this file with your own paths filled in.
Next
- CI pipelines: sync and pull automatically.
- CLI reference: every command and flag.