Selecting the application language
The language combo box is the simplest way to let users change languages at runtime. It needs no population code and no event wiring: it reads the available languages from the Localizer, shows one entry per language, pre-selects the active one, and switches the application language when the user picks a different entry. This guide explains what the combo lists, how selection works, and how to react to a change when you have UI that is not translated automatically. Reach for it once your translations are loaded; if you have not set the localizer up yet, start with the Localizer getting started.
What the combo lists
Each row is one available language, shown using its full description (for example English, Deutsch, Français, Nederlands). Languages the translation set marks as excluded are left out, and the entry matching the localizer's current target language is selected automatically. The list rebuilds itself whenever the set of languages or the active language changes, so you never populate or refresh it manually.
How selecting an entry switches the language
Picking a row activates that language immediately — the combo asks the localizer to set the selected language, which re-localizes the application. There is nothing to call yourself; dropping the combo next to a localizer that has translations loaded is enough for a fully working language switcher.
Reacting to a language change
Because the combo drives the localizer, use the localizer's OnLanguageChange event to refresh anything that is not translated automatically (a custom status bar, a chart legend built in code, and so on). The handler runs whenever the user changes the selection:
procedure TForm1.FormCreate(Sender: TObject);
begin
{ The combo box switches the language on its own; use the localizer event
to refresh anything that is not translated automatically. }
Localizer.OnLanguageChange := HandleLanguageChange;
end;
procedure TForm1.HandleLanguageChange(Sender: TObject);
begin
{ Runs whenever the user picks a language in the combo box. }
UpdateStatusBar;
end;
This combines the combo box (language selection) with the localizer (change notification) so custom UI stays in sync with the built-in translation.
Putting it together: a complete language picker
A working language picker is a localizer plus the combo box plus a change handler, wired together. The following sets all three up in one form-create handler — the localizer supplies and applies the translations, the combo lists the languages and switches on selection, and the handler refreshes custom UI:
procedure TForm1.FormCreate(Sender: TObject);
begin
{ 1. A localizer supplies the languages and applies translations. }
Localizer := TTMSFNCLocalizationLocalizer.Create(Self);
Localizer.LocalizationFolder := 'Translations';
Localizer.OnLanguageChange := HandleLanguageChange;
{ 2. The combo box lists those languages and switches on selection. }
FLanguages := TTMSFNCLocalizationComboBox.Create(Self);
FLanguages.Parent := Self;
FLanguages.Position.X := 16;
FLanguages.Position.Y := 16;
FLanguages.Width := 200;
{ 3. Apply the persisted (or source) language at startup. }
Localizer.PerformLocalization;
end;
procedure TForm1.HandleLanguageChange(Sender: TObject);
begin
{ Runs whenever the user picks a language in the combo box. }
UpdateStatusBar;
end;
Common pitfalls
- Load translations before the combo is shown. The combo lists the languages the localizer knows about; with nothing loaded it comes up empty. Point the localizer at its translation folder or file first.
- Do not translate the combo's own entries. The language names are intentionally shown in their own language (endonyms) so users can recognize their language regardless of the current UI language.
- One localizer per application. The combo talks to the shared localization engine; multiple combos stay in sync automatically, so there is no need to coordinate them.