Skip to content
Okaapiأوكابي
Framework for the code
Theme
Okaapi on GitHub

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.

Use it in Angular
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.

Angular
<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”.

Angular
<ui-language-switcher [languages]="languages" [(current)]="language" />

languages: Language[] = [
  { code: 'en', name: 'English' },
  { code: 'ar', name: 'عربي' },
  { code: 'fr', name: 'Français' },
];

In Arabic

Angular
<ui-language-switcher label="اللغة" size="sm" [languages]="languages" [(current)]="language" />

When to use something else

If you needUse
Any other choice from a listSelect
Switch between views of a pageSegmented control

Inputs

NameTypeDefaultWhat it does
languagesLanguage[] — Required. { code, name }, each name in its own language.
[(current)]string — Required. The current language's code.
labelstring'Language' from labelsThree 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

KeysWhat 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.