<!-- a native <select> of every JVM locale -->
<g:localeSelect name="myLocale" value="${locale}" />
<!-- restrict to the locales the application is translated into, each labelled in its
own language and ordered by that label -->
<g:localeSelect name="myLocale" available="true" labelType="autonym" sort="true" />
<!-- a plain list of links that switch locale via ?lang= -->
<g:localeSelect available="true" type="links" labelType="autonym" />
<!-- body form: supply your own markup (e.g. a Bootstrap dropdown) and reuse the tag's
locale resolution, sorting, autonym labels and active/default detection -->
<g:localeSelect available="true" pinDefault="true" var="loc">
<li><a class="dropdown-item${loc.active ? ' active' : ''}"
href="?lang=${loc.tag}">${loc.autonym}</a></li>
</g:localeSelect>
localeSelect
Purpose
Renders a locale selector. Without a body it produces a control (a native <select> or a list of links); with a body it iterates the locales and renders your own markup for each.
Examples
Description
Without a body the tag renders a control: a native <select> by default, or a plain list of <a> links with type="links". With a body it renders that body once per locale, exposing a per-locale model under the var attribute so you supply your own markup (for example the Bootstrap dropdown in the create-app default layout).
Attributes
-
name- The name to be used for the select box (select mode) -
value(optional) - The selected Locale; defaults to the current request locale if not specified -
available(optional) - Iftrue, lists only the locales the application is actually translated into (those with amessages_*.propertiesbundle on the classpath, as discovered by the i18n plugin) rather than every locale the JVM knows about. Defaults tofalse. -
type(optional) -select(default) orlinks. Ignored when a body is supplied. -
labelType(optional) - The option/link label:autonym(each locale in its own language, e.g.Deutsch),name(in the display locale, e.g.German),both, or omitted for the legacy"language, [COUNTRY,] name"label. -
sort(optional) - Iftrue, orders the locales by their label using a locale-independent collator. -
tags(optional) - Iftrue, option/link keys are BCP‑47 language tags (en-US) rather than the legacyen_USform. -
pinDefault(optional) - Iftrue(body mode), emits the configured default locale (grails.i18n.default.locale, falling back tospring.web.locale) first, so it can be pinned to the top of a switcher. -
param(optional) - The request parameter name used forlinks-mode hrefs. Defaults tolang. -
var(optional) - Enables body mode: the name of the per-locale model variable exposed to the body. The model exposeslocale,tag(BCP‑47),code(language_COUNTRY),autonym(the name in its own language),name(the name in the display locale),label,active(matches the current locale),default(matches the configured default) andindex.