FMXTLang (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example shows how to create a translatable application using TLang. The project is a Multi-Device Application, containing a TListBox with 3 TListBoxItems, a TButton, and a TLang object. The list box items have the Text property set to a two-letter language code. When the user selects an item from the list, the language changes and the translatable string receive a new value. When pressing the button, a Hello message appears.

The form should look like in the following image.

TLang1.jpg

The translated strings can be set using the Language designer. Double-click the TLang object on the form, insert the two-letter language codes, and click Add.

TLang2.jpg

The designer recognizes the translatable strings in the project, but you can also add new ones by clicking the + sign. To write the translations, select the desired language and insert the translated text.

TLang4.jpg

After selecting a language, the text on the button changes. If the user presses the button, a message is displayed.

TLang.JPG

To replicate this project, create event handlers for the button's OnClick event, the form's OnCreate event, and the list box's OnChange event.

Code

// Delphi

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('Hello');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Text := 'Message';
  Form1.Caption := 'FMX TLang';
end;

procedure TForm1.ListBox1Change(Sender: TObject);
begin
  Lang1.Lang := ListBox1.Selected.Text;
end;

Uses