ImageEn, unit hyiedefs

LanguageToStr


Declaration

function LanguageToStr(ALanguage : TMsgLanguage) : string;


Description

Converts a TMsgLanguage to string, e.g. msEnglish would return 'English', msItalian returns 'Italian', etc.
If Localized is true, the language is returned as it would be in that language, e.g. 'Italiano'




Example

// Create a pop up menu to select language
procedure AddLanguagesToMenu(Pop: TPopupMenu; OnClick: TNotifyEvent);
var
  langs: TMsgLanguages;
  i: Integer;
  aLang : TMsgLanguage;
  NewItem: TMenuItem;
begin
  Pop.Items.Clear;
  langs := IEGlobalSettings().GetLanguages();
  for i := Low( langs ) to High( langs ) do
  begin
    aLang := langs[ i ];
    NewItem := TMenuItem.Create( Pop.Owner );
    NewItem.Caption := LanguageToStr( aLang, True );
    NewItem.Hint := format( iemsg( IEMsg_SetLanguageToX ), [ LanguageToStr( aLang , False ) ]);
    NewItem.Checked := IEGlobalSettings.MsgLanguage = aLang;
    NewItem.Tag := ord(aLang);
    NewItem.OnClick := OnClick;
    Pop.Items.Add(NewItem);

    // Add separator for "Default"
    if aLang = msSystem then
    begin
      NewItem := TMenuItem.Create( Pop.Owner );
      NewItem.Caption := '-';
      Pop.Items.Add(NewItem);
    end;
  end;
end;

procedure TfrmMain.LanguageClick(Sender: TObject);
var
  aLang : TMsgLanguage;
  I: Integer;
begin
  for I := 0 to popLanguage.Items.Count - 1 do
    popLanguage.Items[I].Checked := False;
  aLang := TMsgLanguage(TMenuItem(Sender).Tag);

  try
    IEGlobalSettings.MsgLanguage := aLang;
    TMenuItem(Sender).Checked := True;
  except
    MessageDlg( 'IELang32.dll not found! Copy it to the EXE folder for localization support.', mtInformation, [ mbOK ], 0 );
  end;
end;

procedure TfrmMain.PopupLanguageMenuAtControl(Control: TControl);
begin
  if popLanguage.Items.Count = 0 then
    AddLanguagesToMenu( popLanguage, LanguageClick );
  popLanguage.Popup( Control.ClientOrigin.X, Control.ClientOrigin.Y + Control.Height )
end;


See Also

- Language Support
- GetLanguages
- MsgLanguage