All jobs

Add i18n to a React Router App

Yes. An agent adds i18next to a React Router 7 app, detects the language on the server, sets the html lang attribute, translates every string, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads what renders where before it adds a translation layer. In an app shaped like the default template of remix-run/react-router-templates, package.json runs react-router build, react-router dev, react-router-serve ./build/server/index.js and react-router typegen && tsc for typecheck, on react ^19.2.8, @react-router/node, @react-router/serve, vite ^8.0.3 and tailwindcss ^4.2.2. react-router.config.ts keeps ssr: true. app/routes.ts has one route, index("routes/home.tsx"). app/root.tsx renders <html lang="en"> in its Layout, and its ErrorBoundary holds the strings Oops!, An unexpected error occurred., 404 and The requested page could not be found.. app/routes/home.tsx sets the title New React Router App and the description Welcome to React Router! in meta, and app/welcome/welcome.tsx renders What's next?, React Router Docs and Join Discord. There are no entry.client.tsx or entry.server.tsx files; the framework supplies them.

It adds i18next and react-i18next and writes the plumbing itself rather than pulling in a framework adapter, which keeps the dependency list to two packages. app/locales/en.json and app/locales/es.json hold every string above under stable keys; tsconfig.json already sets resolveJsonModule, so the files import with types. app/i18n/config.ts lists the supported languages and the fallback, en. app/i18n/server.ts decides the language for a request in a fixed order: a lng query parameter, then a lng cookie made with createCookie from react-router, then the first supported language in Accept-Language, else en. The root loader in app/root.tsx calls it and returns { locale }, and Layout reads it with useRouteLoaderData("root") to render <html lang={locale}>.

Because i18next needs a per-request instance on the server and one shared instance in the browser, the agent runs npx react-router reveal to write app/entry.server.tsx and app/entry.client.tsx, then wraps the render in each with I18nextProvider: the server creates an instance with i18next.createInstance() for the request's locale, the client initialises once from the lang attribute already in the document, so there is no flash of English. home.tsx, welcome.tsx and the ErrorBoundary switch to useTranslation(), and meta in home.tsx reads the title and description from the loader data so the <title> is translated too. A small routes/set-language.ts resource route takes POST with a language and sets the cookie, and welcome.tsx gains a language switch that posts to it.

English stays the default, so the repository's own Playwright suite in .tests/test.default.ts, which asserts the title matches New React Router App and waits for the React Router Docs and Join Discord links, passes unchanged. Before pushing, the agent runs npm run typecheck, which regenerates the +types for the new route before tsc, then npm run build and npm run start, requests the page with Accept-Language: es and without it, and pastes the two <html lang> values and the translated heading into the pull request.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add internationalisation to this React Router 7 app and open a pull request. Read package.json, react-router.config.ts, app/routes.ts, app/root.tsx, app/routes/home.tsx, app/welcome/welcome.tsx and tsconfig.json first. Add i18next and react-i18next only. Put every user-facing string from root.tsx, home.tsx and welcome.tsx into app/locales/en.json and app/locales/es.json under stable keys. Write app/i18n/config.ts with the supported languages and en as fallback, and app/i18n/server.ts that picks the language from a lng query parameter, then a lng cookie made with createCookie, then Accept-Language, else en. Return { locale } from a root loader and render html lang from it. Run npx react-router reveal and wrap the server and client renders in I18nextProvider, with a per-request instance on the server. Convert the components to useTranslation and translate the meta title and description through loader data. Add a set-language resource route that sets the cookie and a language switch in welcome.tsx. Keep English as the default so the existing Playwright tests in .tests pass unchanged. Run npm run typecheck, npm run build and npm run start, request the page with and without Accept-Language: es, and paste both html lang values and the translated heading in the pull request. Do not change the Dockerfile or Tailwind setup.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request with two new dependencies, app/locales/en.json and es.json, app/i18n/config.ts and server.ts, revealed app/entry.server.tsx and app/entry.client.tsx, a new routes/set-language.ts registered in app/routes.ts, and edits to root.tsx, home.tsx and welcome.tsx. The description shows the <html lang="en"> and <html lang="es"> responses, the translated heading, and the output of npm run typecheck and npm run build.

A browser with English or no preference sees the same page as before, title included, so the template's Playwright checks keep passing. A browser with Spanish first in Accept-Language gets the Spanish strings on the first server render, and the switch sets a cookie that wins over the header afterwards.

A reviewer checks the detection order, that the cookie is httpOnly and sameSite, that the keys in both JSON files match, that entry.server.tsx builds a new i18next instance per request rather than sharing one, and that no string is left in a component. Then they add the next locale file.

Run it on every new locale requested

Once the plumbing is in, each new language is one more run: POST /o/{org}/sessions with a prompt that names the locale and the repository in resources. The agent adds app/locales/<lng>.json with every key from en.json, registers it in app/i18n/config.ts, runs typecheck and build, and opens a pull request for a native speaker to review the wording.

Give the API key a webhook_url and Rush POSTs run.completed when each turn ends, with the session_url to read the pull request from.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Adding i18n to a server-rendered app is mostly wiring: the language must be decided on the server, carried into the first render, and picked up by the client without a second render in another language. In a Rush sandbox the agent builds and starts the app, requests it with two Accept-Language headers, and keeps both responses in the run's record, so the pull request shows the server-rendered lang attribute change rather than describing it.

The template ships a Playwright suite that asserts English strings, and the agent keeps it green by making English the fallback and proving that with typecheck and build before it pushes. The same request works on any React Router 7 app, with more routes meaning more keys and the same plumbing.

Frequently asked questions

Why not use remix-i18next?

It is a fine choice and the agent will use it if the prompt asks. The default here is i18next plus react-i18next with a short detector written in the repository, because it keeps the dependency list to two packages and leaves nothing hidden behind an adapter.

Will there be a flash of English before the translation loads?

No. The server renders the page in the detected language and the client initialises i18next from the lang attribute already in the document, with the resources bundled, so the first paint and hydration agree.

How does a visitor switch language?

The switch in welcome.tsx posts to the set-language resource route, which sets a lng cookie and redirects back. The cookie is read before Accept-Language, so the choice sticks across visits; ?lng=es on any URL overrides both for that request.

Does the existing Playwright suite still pass?

Yes. .tests/test.default.ts runs with no Accept-Language preference, so it gets English, and the title New React Router App and the two link names are unchanged in en.json.

More React Router jobs

The same job on other stacks

Keep reading