Chapter 07 Navigation
Language switcher
Switches the interface language. Each language is named in itself, so someone who reads only that language can find it, and carries its lang, so screen readers say it in the right voice. No flags: a flag is a country, not a language. Set lang and dir on the html element when the language changes.
import { LanguageSwitcherComponent, type Language } from '@okaapi-ui/angular';
// Three or more languages use the Angular CDK menu. Add @angular/cdk/overlay-prebuilt.css.Works with
Two languages
One button that names the other language.
<ui-language-switcher [languages]="languages" [(current)]="language" />
languages: Language[] = [
{ code: 'en', name: 'English' },
{ code: 'ar', name: 'عربي' },
];
language = signal('en');Three or more
A menu with the current language checked. The button reads its label first: “Language: English”.
<ui-language-switcher [languages]="languages" [(current)]="language" />
languages: Language[] = [
{ code: 'en', name: 'English' },
{ code: 'ar', name: 'عربي' },
{ code: 'fr', name: 'Français' },
];In Arabic
<ui-language-switcher label="اللغة" size="sm" [languages]="languages" [(current)]="language" />When to use something else
| If you need | Use |
|---|---|
| Any other choice from a list | Select |
| Switch between views of a page | Segmented control |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
languages | Language[] | — | Required. { code, name }, each name in its own language. |
[(current)] | string | — | Required. The current language's code. |
label | string | 'Language' from labels | Three or more: read before the current name on the button, and the menu’s name. Translate it. |
size | 'sm' | 'md' | 'lg' | 'md' | The button's size. |
Keyboard and screen readers
| Keys | What they do |
|---|---|
| Enter or Space or Down | Open the list of languages. |
| Up or Down | Move through the languages. |
| Escape | Close it, and put focus back on the button. |
- Each language is named in itself and carries its lang, so it is read in the right voice.