# Add i18n to a Leptos App

Yes. An agent adds leptos_i18n to a Leptos 0.8 Axum app: locale files, a build script, a context provider, locale-prefixed routes and a Playwright check, then a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-i18n/leptos/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the app before it adds a crate. In a project generated from leptos-rs/start-axum, `Cargo.toml` depends on `leptos`, `leptos_router` and `leptos_meta` at 0.8, with `axum` 0.8, `leptos_axum` and `tokio` behind the `ssr` feature and `wasm-bindgen` plus `console_error_panic_hook` behind `hydrate`; the crate is both `cdylib` and `rlib`, and `[package.metadata.leptos]` names the output, `style/main.scss`, the `public` assets directory, `site-addr = "127.0.0.1:3000"`, and `end2end-cmd = "npx playwright test"` in `end2end/`. `src/main.rs` builds an Axum `Router` with `leptos_routes` and `file_and_error_handler(shell)`; `src/lib.rs` exposes `hydrate`; `src/app.rs` has a `shell` with `<html lang="en">`, an `App` that calls `provide_meta_context`, sets `<Title text="Welcome to Leptos"/>` and routes `StaticSegment("")` to `HomePage`, whose `RwSignal` counter renders `"Click Me: " {count}`. `end2end/tests/example.spec.ts` asserts that title and the `h1` text. Every string the user sees lives in `app.rs`.

`leptos_i18n` 0.6 is the crate for Leptos 0.8 and it requires `leptos` 0.8.15 or later, so the first command is `cargo update -p leptos` to bring the template's `0.8.0` requirement to the current patch. The agent adds `leptos_i18n = "0.6"` to `[dependencies]` and `leptos_i18n_build = "0.6"` to `[build-dependencies]`, and extends the two feature sets the way the crate's book says: `ssr` gains `"leptos_i18n/axum"` and `"leptos_i18n_build/ssr"`, `hydrate` gains `"leptos_i18n/hydrate"` and `"leptos_i18n_build/hydrate"`. A new `build.rs` calls `Config::new("en")?.add_locale("fr")?`, parses with `TranslationsInfos::parse`, emits diagnostics and `rerun-if-changed` lines for the locale files, and writes the generated module into `OUT_DIR/i18n`; `src/lib.rs` includes it with `include!(concat!(env!("OUT_DIR"), "/i18n/mod.rs"))`, which is where `Locale`, `I18nContextProvider`, `use_i18n` and the `t!` macro come from.

The translations go in `locales/en.json` and `locales/fr.json`, and the agent moves every string from `app.rs` into them: `title`, `welcome` for the heading and `click_count` with an interpolation, written as `"You clicked {{ count }} times"` in the file and used as `t!(i18n, click_count, count = move || count.get())`. A key missing from one locale is a compile error, which is the point of the crate. `App` wraps its router in `<I18nContextProvider>`; the `<Title>` and the `h1` read through `use_i18n()`; and a small `LocaleSwitch` component calls `i18n.set_locale(Locale::fr)`, which also stores the choice in a cookie because the `cookie` feature is on by default. The `lang` attribute on `<html>` follows the current locale through `leptos_meta`'s `<Html>` component, since a fixed `lang="en"` on a French page is the first thing an accessibility check flags.

For URLs, the agent adds `leptos_i18n_router` and replaces the `Route` with `<I18nRoute<Locale, _, _> view=Outlet>` around it, so `/` and `/fr` both serve the home page, a visitor whose cookie or `Accept-Language` says French is redirected from `/` to `/fr`, and switching back to the default locale drops the prefix. The Playwright test is updated for the English title and extended with a `/fr` case that checks the French heading. It runs `cargo leptos build`, then `cargo leptos end-to-end`, which builds, serves on port 3000 and runs the suite, and opens the pull request when both pass.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add internationalisation to this Leptos 0.8 application with leptos_i18n, with French as the first second language. Read Cargo.toml, src/main.rs, src/lib.rs, src/app.rs, style/main.scss, end2end/playwright.config.ts and end2end/tests first. Update leptos to the patch release leptos_i18n 0.6 needs, add leptos_i18n and leptos_i18n_build with the axum, ssr and hydrate features on the matching feature sets, write a build.rs that declares en as the default locale and fr as a second one and generates the i18n module into OUT_DIR, and include that module from lib.rs. Move every user-visible string in app.rs into locales/en.json and locales/fr.json, using an interpolation for the counter, wrap the app in I18nContextProvider, read strings with the t! macro, make the html lang attribute follow the locale, add a locale switch component, and use leptos_i18n_router's I18nRoute so each locale has a URL prefix. Update the Playwright test for both locales, run cargo leptos build and cargo leptos end-to-end until they pass, and open a pull request that lists the keys and quotes the test output.",
  "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

The pull request changes `Cargo.toml` and `Cargo.lock`, adds `build.rs`, `locales/en.json` and `locales/fr.json`, changes `src/lib.rs` and `src/app.rs`, and updates `end2end/tests/example.spec.ts`. Its description lists every translation key with both values, names the locale resolution order the crate applies (URL prefix, then cookie, then `Accept-Language`, then the browser's languages, then the default), and quotes the Playwright output.

A reviewer who reads French checks the two or three translated strings; everyone checks that the `t!` calls cover every string that was in `app.rs`, that the switch component renders in both server and hydrated modes, and that the `/fr` route and the redirect behave as the test says. Because the keys are checked at compile time, a missing translation is a build failure rather than a blank in production.

From then on a new string is a key in two JSON files and a `t!` call, and a new language is one `add_locale` line plus a file, with the compiler listing every key that file still lacks.

## Run it on every new language request

A maintainer who takes language requests as GitHub issues adds an automation to the Project with a `github` trigger on `issues.labeled`, the label `i18n`, and this prompt with the language left to the issue. The trigger appends the issue after the prompt and fills in no placeholder, so the agent reads the locale from the issue text ("German" becomes `add_locale("de")` and `locales/de.json`) while the prompt stays fixed. Only an issue labelled by an owner, member or collaborator fires it, and the automation's `max_runs_per_hour` caps how many it starts in an hour.

A team with several Leptos front ends sends this body once per repository from its own server, each a `POST /o/{org}/sessions` with that repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name, so a retried call returns the run already started. Each run reads its own `Cargo.toml`: an Actix app gets the `actix` feature instead of `axum`, an app already on leptos_i18n gets only the new locale file, and an app with many routes gets each of them inside the `I18nRoute`.

## Why run it on Rush?

Leptos i18n is compile-time work: a build script, feature flags that must line up across `ssr` and `hydrate`, a generated module, and routes that change shape. Each of those fails loudly only when the whole thing is built both ways and served, which is what `cargo leptos end-to-end` does and what the agent runs in its own sandbox with the WebAssembly target and Playwright installed, so the output comes back with the pull request.

The same request applies to every Leptos app a team owns, and each run reads its own `app.rs` to find the strings and its own `Cargo.toml` to pick the backend feature. Starting them all at once turns a project-by-project chore into a set of small pull requests reviewed together.

## Frequently asked questions

### Why does leptos itself get updated?

leptos_i18n 0.6 declares `leptos ^0.8.15`, and the template's `Cargo.toml` asks for `0.8.0`, which the lockfile may still resolve to an older patch. `cargo update -p leptos` moves it within 0.8, so no API changes follow. An app on Leptos 0.7 would need leptos_i18n 0.5 instead, and the agent says which it used.

### What happens if a key is missing in one language?

The build fails. `leptos_i18n_build` parses every locale file in `build.rs` and reports a key that exists in `en.json` but not in `fr.json`, so a half-translated app never ships silently. That is also why the agent moves every string in one pass rather than a few.

### How is the visitor's language chosen?

In order: a locale prefix in the URL, a cookie set the last time they switched, the `Accept-Language` header on the server, the browser's languages on the client, then the default. With `I18nRoute`, a visitor resolved to French who opens `/` is redirected to `/fr`, and switching back to English removes the prefix.

### Does this work without the router prefix?

Yes. `I18nContextProvider` and the `t!` macro work on their own, with the cookie and headers deciding the locale and the URL unchanged. The prefix makes each language linkable and crawlable, which is why the prompt asks for it, but a follow-up message can remove the `I18nRoute` wrapper if the app wants one URL per page.

## More Leptos jobs

- [Add Open Graph Tags to a Leptos App](https://getrush.ai/run/add-open-graph-tags/leptos/)
- [Add Prometheus Metrics to a Leptos App](https://getrush.ai/run/add-prometheus-metrics/leptos/)
- [Add Rate Limiting to a Leptos Server](https://getrush.ai/run/add-rate-limiting/leptos/)

## The same job on other stacks

- [Add Localization to a Lit Web Component with @lit/localize](https://getrush.ai/run/add-i18n/lit/)
- [Add i18n to an mdBook Site](https://getrush.ai/run/add-i18n/mdbook/)
- [Add i18n to a MkDocs Site](https://getrush.ai/run/add-i18n/mkdocs/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
