Internationalization
Files: src/config/language.json, src/config/config.toml, src/i18n/, src/config/menu.*.json, src/content/**/<language>/ · Skill level: Beginner
In the Tina edition, each entry at /admin/ has one folder or file per language, and Menus and Interface labels have one file per language. In the Sanity edition, each language is an entry under Content in the Studio, with its own documents, Menus, and Interface labels. language.json stays in the project in every edition.
Consultiz ships in English (the default, at /), French (at /fr/), and Arabic (at /ar/). Every page, menu, and label exists in every language. Arabic is the right-to-left example: the whole layout mirrors on /ar/ pages. See RTL & Arabic.
What Makes Up A Language
| Part | Files, with French as the example |
|---|---|
| The language itself | An entry in src/config/language.json |
| Page and section text | A folder per language in every content folder: src/content/sections/french/, src/content/blog/french/, … |
| Interface text | src/i18n/fr.json (labels, form messages, footer text, address and hours) |
| Menus | src/config/menu.fr.json |
In src/config/language.json:
[ { "languageName": "English", "languageCode": "en", "contentDir": "english", "dir": "ltr", "ogLocale": "en_US", "dateLocale": "en-GB", "weight": 1 }, { "languageName": "Français", "languageCode": "fr", "contentDir": "french", "dir": "ltr", "ogLocale": "fr_FR", "dateLocale": "fr-FR", "weight": 2 }, { "languageName": "العربية", "languageCode": "ar", "contentDir": "arabic", "dir": "rtl", "ogLocale": "ar_SA", "dateLocale": "ar", "weight": 3 }]languageName is shown in the language switch, languageCode is the URL prefix and the file suffix (fr.json, menu.fr.json), contentDir is the folder name inside each content folder, dir sets the direction, ogLocale is the Open Graph locale, and dateLocale sets the date format.
Language Settings
[settings.multilingual] enable = true defaultLanguage = "en" disableLanguages = [""] # for example ["ar"] showDefaultLangInUrl = false # true gives /en/pricing/ instead of /pricing/Restart npm run dev after any change here. These settings stay in config.toml in the Sanity edition too.
Remove A Language
-
Turn one language off, keep its files. Add its code to
disableLanguages, for example["ar"]. It is no longer built. You can turn it back on any time. This is the same in every edition. -
Use only your default language, keep the files. Set
enable = false. Only the default language is built and the language switch disappears. -
Delete every other language for good. In the Astro and Tina editions, first set
enable = falseand runnpm run devonce. Then save a checkpoint (a git commit or a copy of the folder) and run:Terminal window npm run remove-multilingualIt keeps your default language, whichever it is. It deletes the content folders,
src/i18n/files, andsrc/config/menu.*.jsonfiles of every other language, and removes them fromlanguage.json. This can’t be undone without your checkpoint.In the Sanity edition, the same command updates
language.jsonand the bundled sample content. Your project keeps the other languages’ documents unless you add-- --delete-online, which deletes them and can’t be undone.
Add A Language
The language script adds the language to language.json and copies your default language as a starting point. These steps add German.
-
Run the script. In the Astro and Tina editions:
Terminal window npm run generate-multilingual-content -- --lang de --name Deutsch --dir-name german --locale de-DE --og de_DEIn the Sanity edition the last flag is called
--og-locale:Terminal window 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. In the Astro and Tina editions, your existing translations are kept unless you add--force. In the Sanity edition, with a project connected, it also creates the new documents and leaves your existing ones alone. -
In the Tina edition, run
npm run tina:generate, thennpm run devonce, so the editor shows the language. -
Translate the new content, menu, and interface labels. Keep every key as it is. In the Astro and Tina editions, these are the new
german/content folders,src/config/menu.de.json, andsrc/i18n/de.json. In the Sanity edition, they are the new language’s documents in the Studio. -
On Netlify, add a
/de/*block tonetlify.toml, like the French one. The script doesn’t change that file. -
Restart
npm run devand open/de/.
Directorysrc/content/
Directorysections/
Directoryenglish/
- …
Directoryfrench/
- …
Directoryarabic/
- …
Directorygerman/
- …
Directoryblog/
Directoryenglish/
- …
Directoryfrench/
- …
Directoryarabic/
- …
Directorygerman/
- …
For a right-to-left language, also see RTL & Arabic.
Links Between Pages
- In menus and in
urlfields of buttons and links in content files, write the English path (/pricing/). Consultiz adds the language prefix for you. - In Markdown text (the body of a post or page), write the full path for that language yourself:
[see pricing](/fr/pricing/)in a French file. - Give each page the same file name in every language, and the same
customSlugif you use one, so the language switch finds the matching page. - The case study list page in a translated language can leave out fields: missing ones fall back to the English
-index.md.
Translated 404 Pages
Each language has its own 404 page (/fr/404.html, /ar/404.html). On Netlify, the redirects in netlify.toml send a missing /fr/... or /ar/... address to it. Add one block per extra language. Other hosts show the default 404 page for every language unless you set up a similar rule.
Interface Text
Labels that are not page content live in src/i18n/<lang>.json, for example the blog post details: blog.minutesRead ("{count} min read"), blog.lastUpdate, and blog.defaultAuthor (shown for posts without an author, or with author: "admin"). The site tagline is common.tagline when [site] tagline is empty. Translate these files along with your content, in every language.
Do It With AI
Add [LANGUAGE] ([CODE]) to the site. Use npm run generate-multilingual-content with the flags inREADME.md, and add --dir rtl if it is a right-to-left language. Translate the new content folders,the menu file, and the i18n file, keeping every key. Add a /[CODE]/* block to netlify.toml. Then runnpm run astro-check and list the pages I should check by eye.