Internationalization
Files: src/config/language.json, src/config/config.toml, src/i18n/, src/config/menu.*.json, src/content/**/<language>/ · Skill level: Beginner
Consultiz ships in English (the default, at /) and French (at /fr/). Every page, menu, and label exists in both. Right-to-left languages are not supported.
What Makes Up A Language
| Part | Files |
|---|---|
| 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) |
| Menus | src/config/menu.fr.json |
In src/config/language.json:
[ { "languageName": "English", "languageCode": "en", "ogLocale": "en_US", "contentDir": "english", "weight": 1 }, { "languageName": "Français", "languageCode": "fr", "ogLocale": "fr_FR", "contentDir": "french", "weight": 2 }]languageName is shown in the language switch, languageCode is the URL prefix and the file suffix (fr.json, menu.fr.json), ogLocale is the Open Graph locale, and contentDir is the folder name inside each content folder.
Language Settings
[settings.multilingual] enable = true defaultLanguage = "en" disableLanguages = [""] # for example ["fr"] showDefaultLangInUrl = false # true gives /en/pricing/ instead of /pricing/Restart npm run dev after any change here.
Use English Only
You have two options:
-
Turn French off, keep the files. Set
enable = false(ordisableLanguages = ["fr"]). Only English is built and the language switch disappears. You can turn French back on any time. -
Delete French for good. First set
enable = falseand runnpm run devornpm run astro-checkonce, so.astro/config.generated.jsonexists (the script reads your default language from it). Then save a checkpoint (a git commit or a copy of the folder) and run:Terminal window npm run remove-multilingualIt deletes every
french/content folder,src/i18n/fr.json, andsrc/config/menu.fr.json, and removes French fromlanguage.json. This can’t be undone without your checkpoint.
Replace French With Another Language
The easiest way to get a Spanish (or German, or Dutch) site is to turn the French copy into it:
-
In
language.json, change the French entry to"languageName": "Español","languageCode": "es","ogLocale": "es_ES","contentDir": "spanish". -
Rename every
src/content/**/french/folder tospanish/. -
Rename
src/i18n/fr.jsontoes.jsonandsrc/config/menu.fr.jsontomenu.es.json. -
Translate the text values in those files and folders. Keep every key as it is, and change internal links in Markdown text from
/fr/to/es/. -
In
netlify.toml, change the/fr/*redirect to/es/*and/es/404.html. -
Restart
npm run devand open/es/.
Add A Third Language
-
Add an entry to
language.json, for example{ "languageName": "Deutsch", "languageCode": "de", "ogLocale": "de_DE", "contentDir": "german", "weight": 3 }. -
Copy
src/i18n/en.jsontode.jsonandsrc/config/menu.en.jsontomenu.de.json, then translate them. -
In every content folder that has an
english/folder, create agerman/copy and translate it. -
On Netlify, add a redirect block for
/de/*tonetlify.toml, like the French one. -
Restart
npm run devand open/de/.
Directorysrc/content/
Directorysections/
Directoryenglish/
- …
Directoryfrench/
- …
Directorygerman/
- …
Directoryblog/
Directoryenglish/
- …
Directoryfrench/
- …
Directorygerman/
- …
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 French 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). On Netlify, the redirect in netlify.toml sends a missing /fr/... address to it; add one block per extra language. Other hosts show the default (English) 404 page for every language unless you set up a similar rule.
Interface Text
Labels that are not page content live in src/i18n/en.json and fr.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.