Languages: run the site in more than one language
Describes PhoenixKit 3.6.1. On an older release? The version menu above has this guide as it was then.
A PhoenixKit site is written in one primary language. Turn on multiple languages and visitors can use it in others too: each language gets its own URLs, a language switcher appears, and content can be translated.
Where to find it
Settings → Languages (/admin/settings/languages). You need the Languages permission, or the Owner or Admin role. The page is always there, whether the site has one language or many. Settings → General shows the primary language under Language & URLs, with a link here.
Settings → Languages.
Multiple languages
The first card, Multiple languages, is the site’s switch: Let visitors use the site in more than one language: locale-prefixed URLs, a language switcher and translated content.
- Off (the default): the site is served in its primary language only, no URL carries a language segment, and no switcher or menu offers a language. Old public links with a language segment redirect to the clean address.
- On: the site serves the languages you enable below. The first time you turn it on, the primary language is enabled and keeps its URLs without a prefix, so nothing changes for existing links.
Turning it off keeps the list of languages you chose: turning it on again brings it back.
Primary language & URLs
Primary language is the language the site is written in: its content, its interface, and the language every URL falls back to. It can be set with the switch off too.
With multiple languages on, Primary language without prefix decides whether the primary language has a language segment in its URLs. On, it drops it (/blog/post instead of /en/blog/post); other languages always keep their prefix.
Choosing the languages
With multiple languages on, the page shows two more cards.
Summary counts Languages Enabled and Countries Covered, and lists the Enabled Languages, with the default language marked Default language. Each language there can be made the default with Set Default or turned off with Disable. Reorder lets you drag them into the order switchers list them; each move is saved, and Done closes the reorder list.
Available Languages lists every language PhoenixKit knows, grouped by continent and country, with a search box (Search countries or languages…). Each language has a switch to enable or disable it, and Set Default for an enabled one.
The default language cannot be disabled: it is what the site falls back to.
The language switcher
Visitors change language with a switcher. In the admin, people change their own language in the Language section of the account menu (the avatar in the header); the choice is saved for them. That section only appears when the site has two or more languages.
When more than seven languages are enabled, the switcher first asks for a continent, then the language.
The Frontend Language Switcher card helps a developer put a switcher on the site’s own pages. Switcher Settings (Show Flags, Show Names, Native Names, Go to Home, Hide Current) change the Live Preview and the Generated Code to copy into a template. Only enabled languages appear in the switcher.
What gets translated
Turning on languages does not translate anything by itself. For your content, features that support it show a tab per language:
- In the media library, a file’s title, alt text and description have a tab per language (see the guide on file details).
- Modules that keep content (for example entities and blog posts) store a version per language.
What it doesn’t do
- It does not translate text automatically.
- The default language cannot be removed or disabled.
- With multiple languages off, saved language choices are kept but nothing offers them.
For developers
The sign-in, sign-up, password, sign-out and social sign-in addresses without a language prefix (such as POST /users/log-in) answer in the primary language, so their messages and redirects follow it. Since 3.6.1 the app no longer needs config :gettext, :default_locale set to the site’s language for this.
In code, ask PhoenixKit.Modules.Languages.primary_language_code/0 for the site’s language: it works whether multiple languages are on or off. A switcher built in a template should list Languages.get_enabled_languages/0, never get_display_languages/0, which returns a built-in sample list while the switch is off.