With your agent / Existing site or app
Add a second language to your site or app
“All our texts are written into the code. Add German.”
For whoever has a working site or app in one language, with the texts inside the components, and wants a second language without going through every file by hand.
Prompt
Replace the part in brackets, then paste it into your agent
Localize this app with i18next, in [English and German]. Run `npx i18next-cli localize --print-agent-prompt` and follow the steps it prints, in order, checking each one before the next.
The command prints the steps for the i18next-cli version it runs, so the prompt does not go stale. When the project has no i18next configuration yet, your agent asks you one question before it writes one: where the translation files live.
What your agent does
- Checks the stack. React and Next work as they are; Vue and Svelte need a community plugin for i18next-cli. In Astro,
instrumentdoes not read.astrofiles, so your agent writes thet()calls, and i18next-cli-plugin-astro letsextract,statusandlintread them. - Writes the configuration (
i18next.config.ts, or.jsin a JavaScript project) with your languages:npx i18next-cli init --yes --locales en,de --backend local. - Runs
npx i18next-cli instrument --dry-run, theninstrument: the hardcoded texts go throught()(in Next,await getT()in Server Components anduseT()in Client Components). It lists the texts it left, and your agent moves those; it checks the diff and the warnings before it commits. - Runs
npx i18next-cli extract: every key lands in one JSON file per language and namespace. - Translates the new language, then runs
npx i18next-cli status(no text missing in any language) andnpx i18next-cli lint(it warns when a translation drops a placeholder of the English).
Before it goes live
- Have the new language read by someone who speaks it. An agent's translation is a first draft.
- Look at the pages with the longest texts: German words are longer, buttons and table heads may wrap.
- Add
npx i18next-cli statusto CI, so a text added later without its translation stops the build.
Writing the code yourself? Getting started and the i18next-cli docs describe each command.