Example of Creating a Multilingual Form

This example describes how to create a multilingual form. First, resources are created and a form is created. Following this the resources and the form will be set up for using two interface languages: Russian and English.

Creating Resources

  1. Create the Resources object. Select the Create > Development Environment > Resources item in the object navigator's context menu. The resource editor dialog box opens:

By default, resources contain a language that matches the default repository language. The example displays the Russian language option.

  1. Add a language, to which the form is translated. Select the File > Add Language item in the resources' main menu. The dialog box opens:

  1. Select the English (United States) value in the Select Language list and click the OK button. A new language is added to the resources.

  2. Save the resources. Select the File > Save item in the resources' main menu. The Save Resources dialog box opens:

    1. Specify the ResForAppl resources' name in the Object Name box.

    2. Specify the ResForAppl resources' identifier in the Identifier box.

    3. Select the repository folder, which will store the resources.

Therefore, the resources for working with languages are created in the repository.

Creating a Form

  1. Create a form. Select the Create > Development Environment > Form item in the object navigator's context menu. The Create Object dialog box opens:

    1. Specify the LngForm form name in the Name box.

    2. Specify the LngForm form identifier in the Identifier box.

After clicking the OK button the development environment window opens.

  1. Go to the object inspector and find the Resources property:

  1. Select the Resources property and click the button. The Select Resource dialog box opens.

  2. Specify the previously created ResForAppl resources in this dialog box and click the OK button. This adds the additional ResourcesID attribute to string data type properties of all visual components in the object inspector. This attribute value is generated automatically:

  1. Place the following components on the form:

    1. GroupBox.

    2. Place two RadioButton components on the GroupBox component.

    3. Place the ImageBox component below the GroupBox component.

The form will look as follows:

  1. In the object inspector set the value for the Text property for the form and components:

Component name Value of the Text property
LngForm Change language
GroupBox1 Language
RadioButton1 Russian
RadioButton2 English

Thus, the created form looks as follows:

Translating Resources

  1. Go to the created ResForAppl resources in the object navigator. Double-click the resources with the main mouse button or select the Edit context menu item. The resources are opened for edit.

  2. Select translation language. Select the English (United States) option in the drop-down list on the toolbar:

The column for translation into English is displayed in the resource editor:

The resource editor already includes row elements matching the text properties of the visual components of the form. The element identifier matches the ResourcesID attribute value, whereas the element value for the default language matches the Text property value.

  1. Set element values for translation language. Go to the corresponding element's row cell and enter translation. Translation of elements are shown in the table:

Element identifier Default language value (Russian) Translation language value (English (United States))
LngForm.LngForm Change language Change language
LngForm.GroupBox1 Language Language
GroupBox1.RadioButton1 Russian Russian
GroupBox1.RadioButton2 English English
  1. Add a graphic element for default language to resources:

    1. Go to the Image tab.

    2. Click the button on the toolbar. A standard file open dialog box opens.

    3. Select the image to add to resources.

  2. Change image identifier:

    1. Double-click on it with the main mouse button. The identifier is switched to the edit mode.

    2. Enter the identifier: IMG_1.

    3. Press the ENTER key or click empty space on the tab.

  1. Add an image for the translation language:

    1. Double-click with the main mouse button on the [Image] element located in the English (United States) column. The Edit Image dialog box opens.

    2. Click the Edit button. A standard file open dialog box opens.

    3. Select the image to add to resources.

  2. Save the resources. Select the File > Save item in the resources' main menu.

Thus, resources are translated.

Setting Up Form

  1. Go to the LngForm created form in the object navigator. Double-click the form with the main mouse button or select the Edit context menu item. The form is opened in the development environment.

  2. Add links to the IO and Metabase system assemblies:

    1. Select the Assembly > Edit Links item in the development environment's main menu.

    2. Select checkboxes next to the corresponding assemblies on the System Assemblies tab in the dialog box that opens.

  3. Create a common handler of the OnClick event for the RadioButton1 and RadioButton2 components.

    1. Select the RadioButton1 component in the object inspector and go to the Events tab.

    2. Double-click the cell corresponding to the OnClick event. An event handler with the RadioButton1OnClick name is created.

    3. Change handler's name to RadioButtonOnClick on the Events tab.

    4. Select the RadioButton2 component in the object inspector.

    5. Select a handler with the RadioButtonOnClick name for the OnClick event.

Handler text is shown below. The handler checks the selected radio button and sets appropriate language and resources.

  1. Create the OnCreate event handler for the form:

    1. Select a form in the object inspector and go to the Events tab.

    2. Double-click the cell corresponding to the OnCreate event. An event handler with the LNGFormOnCreate name is created.

Handler text is shown below. The handler calls the OnClick event for RadioButton1.

Therefore, on starting the form, components' captions and image in ImageBox1 will match value of the resources' elements for Russian.

Complete code of the form:

Class LNGForm: Form
    GroupBox1: GroupBox;
    RadioButton1: RadioButton;
    RadioButton2: RadioButton;
    ImageBox1: ImageBox;

    Sub LNGFormOnCreate(Sender: Object; Args: IEventArgs);
    Begin
        RadioButton1.Checked := True;
        RadioButtonOnClick(RadioButton1, Null);
    End Sub LNGFormOnCreate;

    Sub RadioButtonOnClick(Sender: Object; Args: IMouseEventArgs);
    Var
        MB: IMetabase;
        Res: IResourceObject;
        ResSt: IResourceStrings;
    Begin
        MB := MetabaseClass.Active;
        If (Sender As IRadioButton) = RadioButton1 Then
            MB.CurrentLocale := LocaleCodeID.Russian;
        Else
            MB.CurrentLocale := LocaleCodeID.English_UnitedStates;
        End If;
        Res := Self.Resources;
        ResSt := Res.Locales.CurrentLocale.Strings;
        Self.Text := ResSt.Value("LNGForm.LNGForm");
        GroupBox1.Text := ResSt.Value("LNGForm.GroupBox1");
        RadioButton1.Text := ResSt.Value("LNGForm.RadioButton1");
        RadioButton2.Text := ResSt.Value("LNGForm.RadioButton2");
        ImageBox1.LoadImageFromStream(Res.Binaries.Value("IMG_1"));
    End Sub RadioButtonOnClick;

End Class LNGForm;

Starting the Form

Press F9 to start the form.

On starting the form or selecting the Russian/Russian radio button the form will look as follows:

On starting the form or selecting the English/English radio button the form will look as follows:

See also:

Developing Multilingual Applications