How to create a translatable application with FireMonkey and C++Builder using FMXTLang

By: Tim DelChiaro

Abstract: This example shows how to create a translatable application using TLang

    FMXTLang (C++)

 

    Language:

    Versions:

 

    Description

The following example shows how to create a translatable application using TLang. The project is a FireMonkey HD Application, containing a TListBox with 3 TListBoxItems, aTButton, 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.

File: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.

File: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.

File:TLang4.jpg

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

File: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

// CPP
void __fastcall TForm2::Button1Click(TObject *Sender)
{
	ShowMessage("Hello");
}
//---------------------------------------------------------------------------
 
void __fastcall TForm2::FormCreate(TObject *Sender)
{
	Button1->Text = "Message";
	Form2->Caption = "FMX TLang";
}
//---------------------------------------------------------------------------
 
void __fastcall TForm2::ListBox1Change(TObject *Sender)
{
	Lang1->Lang = ListBox1->Selected->Text;
}
//---------------------------------------------------------------------------

    Uses

Server Response from: ETNASC03