Internationalization (i18n)
Files: src/config/config.toml, src/config/language.json, src/i18n/<lang>.json, src/config/menu.<lang>.json, src/content/**/<language>/ · Skill level: Beginner
Stella ships in English, French, and Arabic. Arabic is the right-to-left example, so see RTL & Arabic for how direction works. The Arabic text is a machine translation, so have a native speaker review it before you publish.
Everything reads the language list from src/config/language.json, so you never list languages anywhere else. Each language has its own content folder, menu file, and interface labels.
In the Tina edition, you translate in each language’s folder, Menus, and Interface labels at /admin/. In the Sanity edition, content, menus, and interface labels are documents in the Studio, one set per language.
The language list stays in code in all three editions. The settings below are in config.toml. In the Tina edition, they are also under Site settings > Settings > Multilingual, and you restart npm run dev after you change them.
Language Settings
# Restart your server when you change these values[settings.multilingual] enable = true defaultLanguage = "en" disableLanguages = [] # Languages to turn off, such as ["fr", "ar"] showDefaultLangInUrl = false| Setting | What it does |
|---|---|
enable | Turns multiple languages on or off |
defaultLanguage | The primary language |
disableLanguages | Languages to turn off. Their files stay in the project |
showDefaultLangInUrl | Adds the default language’s code to its addresses, such as /en/ |
The Language List
Each language has an entry in src/config/language.json:
{ "languageName": "Fr", "languageCode": "fr", "contentDir": "french", "dir": "ltr", "ogLocale": "fr_FR", "dateLocale": "fr-FR", "weight": 2}dir is ltr or rtl, and it sets the direction of the page. ogLocale is the language code for social previews, and dateLocale sets the format for dates.
Add A Language
Run the language script. This example adds German. In the Astro and Tina editions:
npm run generate-multilingual-content -- --lang de --name Deutsch --dir-name german --locale de-DE --og de_DEIn the Sanity edition, the last setting is called --og-locale:
npm run generate-multilingual-content -- --lang de --name Deutsch --dir-name german --locale de-DE --og-locale de_DEFor a right-to-left language, add --dir rtl.
It adds the language to language.json, and makes copies of your default language to translate. Then:
- Astro: translate the new
german/content folders,src/i18n/de.json, andsrc/config/menu.de.json, then restart the dev server. - Tina: run
npm run tina:generate, restartnpm run dev, and translate the new folders, Menus, and Interface labels in the editor. - Sanity: restart the dev server. The language appears in the Studio, with a copy of every default-language document to translate. Your other documents aren’t touched.
If you host on Netlify, the script doesn’t change netlify.toml, so add a block for the new language yourself. It sends a missing address to that language’s own 404 page:
[[redirects]] from = "/de/*" to = "/de/404/" status = 404Remove One Language
Add its code to disableLanguages, then restart the dev server. To remove Arabic:
[settings.multilingual] disableLanguages = ["ar"]In the Tina edition, also run npm run tina:generate before you restart. The language’s pages go away, but its files stay, and the editor still lists them.
Keep Only Your Default Language
- Astro: set
enable = falsein[settings.multilingual], runnpm run toml:watchonce, then runnpm run remove-multilingual. - Tina: do the same, then run
npm run tina:generate. - Sanity: run
npm run remove-multilingual. The other languages’ documents stay in your project unless you add-- --delete-online, which deletes them and can’t be undone.
If you host on Netlify, also delete the block of any language you remove from netlify.toml.