Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Bought Jack McDade's course on design. Going through it now...and it is SO well done!

— Justin Jackson, Transistor.fm

Locales Tag

Create links to localized content.

Overview

This tag is used to access all the locales any given entry or term is available in. It's most commonly used as a language switcher.

Each locale's system data, as configured in config/statamic/sites.php, is available inside of a locale array.

Examples

Iterating over locales

Loop through in each locale to get URLs to translated versions of an entry or taxonomy term.

<ul>
{{ locales }}
<li><a href="{{ permalink }}">View in {{ locale:name }}</a></li>
{{ /locales }}
</ul>

Targeting a locale

You can also specify a locale directly instead of looping through them all.

{{ locales:fr }}
<a href="{{ permalink }}">View in French</a>
{{ /locales:fr }}

Excluding the entry's locale

You can choose to not show the locale belonging to the entry.

{{ locales self="false" }}
<a href="{{ permalink }}">View in {{ locale:name }}</a>
{{ /locales }}

Parameters

id

string

The ID of the content you want to localize. If left blank, the content will be taken from the context.

sort

string

Sort by one of the keys in your sites.php's sites array. (eg. name or full). If left blank, the order in the file will be maintained. Only applicable in the tag pair.

current_first

boolean *true*

When true, this ensures that the current site locale will be first in the list. Only applicable in the tag pair.

self

boolean *true*

When true, it includes the given entry's locale in the list. Only applicable in the tag pair.

all

boolean *false*

When true, all of the sites will be displayed, even if the entry isn't localized into that site. When the entry is missing, the values (e.g. url) will fall back to the site. Only applicable in the tag pair.

Variables

Variable Type Description

current

string

The handle of the current locale.

is_current

boolean

true if the given locale in the loop is the current one.

locale:handle

string

The system handle for any given locale as set in config/statamic/sites.php.

locale:name

string

The user-friendly name for any given locale as set in config/statamic/sites.php.

locale:full

string

The full, 4 character system locale (e.g. en_US) for any given locale as set in config/statamic/sites.php.

locale:short

string

The short 2 character system locale (e.g. en) for any given locale as set in config/statamic/sites.php.

locale:url

string

The URL as defined in in sites.php.

locale:permalink

string

The absolute URL of the site.

exists

boolean

Whether the entry has been localized into the site. It will be false if the entry hasn't been localized at all, or if it's a draft.

entry data

mixed

Each result has access to all the variables inside that entry (title, content, etc).

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →