Design a custom locale switcher for efficient navigation between your site’s locales.
Once you’ve published your localized site, you’ll want to build a way for your site visitors to select the right locale or language that meets their needs. With the Locales list element, you can build a locale switcher. The Locales list element works similarly to the Collection list element and displays all locales that have publishing enabled.
You can customize the design however you like, but here, we’ll cover how to build a locale switcher dropdown in a navbar, where the dropdown text indicates the current locale.
Before you get started
Check out the Localization overview to familiarize yourself with Localization. Make sure you’re editing your primary locale when building the locale switcher (i.e., make sure you’ve chosen your primary locale from the Locale view dropdown). Add a navbar to your site and drag a dropdown element into the navbar.
To build your locale switcher:
- Open the Navigator panel
- Click the arrow next to the dropdown element to show its child elements
- Go to Add panel > Advanced
- Drag a Locales list element into your navbar
- Drag the dropdown element inside the Locales wrapper element (you can use the Navigator to precisely drag-and-drop your element)
- Drag the Locales list inside the dropdown list element
- Delete the dropdown link elements
- Select the text block element inside the dropdown toggle element
- Go to Element settings panel > Text block settings
- Click the purple “dot” icon
- Choose Locale name
- Style your dropdown element and child elements however you want
You can also add an image to your locale switcher to show each locale’s display image (i.e., icon or flag) along with its name:
- Go to Add panel > Media
- Drag an image element inside the dropdown toggle element
- Go to Element settings panel > Image settings
- Click the purple “dot” icon
- Choose Locale image
- Style your image however you want
Now, your locale switcher dropdown will display all locales that have Enable publishing to this subdirectory toggled “on” in Settings panel > Localization, and the dropdown text and image will match the current locale (e.g., “English (United States)”). Locales are automatically added to the published Locales list and the locale switcher when publishing is enabled. Learn more about publishing locales.