Skip to content

Kitto.Html.LanguageSwitcher

KittoX language switcher controller. Renders a flag dropdown that lets the end user change the interface language. Modeled on the ThemeSwitcher: it is a controller dropped into a layout region via YAML (Controller: LanguageSwitcher) and appears identically on the Login view and the Home page.

Unlike the theme (a pure client-side, no-reload preference), the language is a server-side per-session setting driven by gettext, so switching posts to the anonymous endpoint /kx/setlang/{Lang} (TKXSetLangHandler) and reloads the current page in the chosen language.

The list of offered languages is DISCOVERED, not configured: a language is offered when <AppHome>\Locale&lt;code>\LC_MESSAGES holds at least one COMPILED catalog (*.mo), plus English (the source language, which needs no catalog). Two rules matter here:

  • the folder must really carry a .mo. A bare folder, or one holding only .po sources, translates nothing: offering it would let the user pick a language and see the page unchanged.
  • only <AppHome> counts. <SystemHome>\Locale is NOT scanned, because KittoX ships framework catalogs (Kitto.mo) for de/es/it/pt and offering a language on their strength alone yields a half-translated UI: framework chrome translated, every application label still in the source language.

Each language id is mapped to a native display name and an ISO country code for the flag SVG under Resources\flags. Adding a language is therefore a matter of dropping the application's compiled catalog in place.

Renders only when Config.yaml has LanguagePerSession: True and at least two languages are available; otherwise it emits nothing.

Drop in any layout via YAML: Controller: LanguageSwitcher

TKXLanguageInfo record

Descriptor of a selectable interface language: the gettext id (e.g. 'it'), the native display name ('Italiano') and the ISO 3166 country code used to pick the flag SVG ('it').

TKXLanguageCatalog class

Shared helper: discovers the available interface languages from the Locale folders and maps each id to a native name and a flag. Used both by the switcher controller (to render options) and by the setlang endpoint (to validate the requested language).

pascal
class function AvailableCodes: TArray<string>;

Returns the gettext ids of the languages offered by this application: English plus every language that has a catalog folder under AppHome\Locale or SystemHome\Locale. Ordered by a preferred list then alphabetically. Never empty (always contains 'en').

pascal
class function IsAvailable(const ACode: string): Boolean;

True when ACode is one of the AvailableCodes (case-insensitive, region-normalized). Used to validate the setlang request.

pascal
class function NormalizeCode(const ALanguageId: string): string;

Reduces a session language id ('it_IT', 'pt-BR') to its base two-letter id ('it', 'pt'), lowercased. Empty maps to 'en'.

pascal
class function InfoFor(const ACode: string): TKXLanguageInfo;

Native name + flag country code for a language id. Unknown ids fall back to the uppercased code as name and the code itself as flag.

pascal
class function RenderSwitcherHtml(const AHtmlId: string): string;

Renders the flag-dropdown HTML using AHtmlId as the root element id. Returns '' when LanguagePerSession is off or fewer than two languages are available. Shared by the LanguageSwitcher controller (Home page) and by the login form, which embeds it as a labelled field row.

TKXLanguageSwitcherController class

Controller that renders the flag language dropdown. Emits markup only when LanguagePerSession is enabled and more than one language is available. Registered as controller type 'LanguageSwitcher'.

pascal
function Render: string;

Renders the flag language dropdown control.

Released under Apache License, Version 2.0.