Language switcher
The navbar's language switcher: the button shows the current language's flag and code, the panel lists the store's languages.
zb:shop.language-switcher zubazar/ui-pro
This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →
The store's language switcher
The languages come from the store's languages() method; a store with one language draws no switcher.
<zb:shop.language-switcher />
Languages and flags
languages() gives the languages as code => name, and language_flags maps the flags whose country code differs from the language code (gb for en).
// The store class (Storefront)
public function languages(): array
{
return ['tr' => 'Türkçe', 'en' => 'English'];
}
// config/zubazar-ui-pro.php (commerce)
'language_flags' => ['en' => 'gb'],
| Prop | Values |
|---|---|
languages() | Code => name; with fewer than two languages no switcher is drawn |
language_flags | Language code => the flag's country code |
General language switcher
zb:locale-switcher is not tied to the store: it takes the languages, the address and the flags as props.
<zb:locale-switcher
:action="route('locale')"
:locales="['tr' => 'Türkçe', 'en' => 'English', 'de' => 'Deutsch']"
:flags="['en' => 'gb']"
align="start"
/>
Without flags
:flags="false" removes the flags; the button keeps a language icon and the language code.
<zb:locale-switcher :action="route('locale')" :locales="['tr' => 'Türkçe', 'en' => 'English']" :flags="false" align="start" />
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
align | — | end | The panel's alignment: end · start (both components) |
locales | — | [] | zb:locale-switcher: the languages, code => name in that language |
action | — | null | zb:locale-switcher: where the choice is posted (POST, field locale); without it nothing is drawn |
flags | — | [] | zb:locale-switcher: language code => country code, not needed when they match; false: no flags |
current | — | null | zb:locale-switcher: the current language; null: app()->getLocale() |
Developer notes
zb:shop.language-switcheruses the store's languages; the generalzb:locale-switcherunder it takes the languages and the address as props.- When a language is picked, the form posts the
localefield to thelocaleroute; the application keeps the choice (a cookie, the account) and redirects back. - The application defines the
localeroute (Shop::ROUTES); the first preview shows a store with two languages. - The general switcher is not drawn either without
actionor with one language;align="start"aligns the panel with the button's left edge. - For a language with no flag (an unknown country code) the button shows the language icon.