The department of AI agents designed to take the i18n burden off you
- Bring your own AI
- Compatible with
next-intl
- Development: develop your React or Server code as usual, leave hard-coded English strings in code
- Extraction: replace hard-coded strings with
next-intl
API calls, come up with semantically good JSON structure, updateen.json
(main locale file) - Translation: translate the changes in
en.json
into desired languages, update corresponding locale files
The following problems exist that we need to be aware of:
- AI can make mistakes
- Token usage is a concern
The following criteria need to be met:
- Atomic - the AI-generated changes need to be atomic, scoped into some small units of work
- Reviewable - the AI-generated chagnes need to be easily reviewable and modifiable by a human
- Robust - no progress should be lost, no modifications should be applied automatically unless explicitly requried
- Suckless (dare I say) - no bloat / unnecessary features, don't reinvent the wheel, use standard tools where possible, be composable, follow UNIX philosophy
Each agent therefore acts as independent team member, and you should treat them as such. You give them a task and they generate commits in a form of git patches. You can review them, apply, cherry-pick, rebase, squash, open pull requests...
Extractor is a technical agent that is proficient in next-intl.
The main goal of extractor is:
- locate files with unlocalized strings (uses
react/jsx-no-literals
eslint rule under the hood) - replace them in code with
useTranslations/getTranslations
- update main locale file (
en.json
) with extracted messages - update
meta.json
with relevant metadata about component (helpful for translators)
Usage:
$ extractor src/path/to/some/part/of/repo/**/*.tsx
<-- Optional glob to filter files$ git checkout -b i18n
$ git am --3way /tmp/patches/
- From now on, treat commits as performed by another developer
Translator is a non-technical agent that specializes in translations.
The main goal of extractor is:
- review the diff in main locale file
- translate this diff into desired locales, respecting component metadata
meta.json
and existing glossary (e.gde.glossary.json
) - update glossary with new entities
Note that translator takes a diff in main locale file as an input. It is very useful to translate certain commits, ranges of commits.
Usage (translate last 5 commits):
$ git diff HEAD~5 src/messages/en.json | translator pl ru de
<-- First command here grabs the diff of the last 5 commits inen.json
file$ git am --3way /tmp/patches/
To bootstrap a new locale, just generate a diff against /dev/null
:
git diff --no-index /dev/null src/messages/en.json | translator es