{**********************************************}
{   Automatic Translation Unit  -Internal-     }
{   Copyright (c) 2001-2020 by Steema Software }
{**********************************************}
unit TeeTranslateEditor;
{$I TeeDefs.inc}

interface

uses
  Graphics, Forms, Controls, StdCtrls, Buttons, ExtCtrls, SysUtils, Classes;

type
  TAskLanguage = class(TForm)
    LBLangs: TListBox;
    PanelButtons: TPanel;
    Panel2: TPanel;
    Label1: TLabel;
    Panel3: TPanel;
    OKBtn: TButton;
    CancelBtn: TButton;
    procedure FormCreate(Sender: TObject);
    procedure OKBtnClick(Sender: TObject);
    procedure LBLangsDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

// Show a dialog to change current Language. Returns True if changed.
Function TeeAskLanguage:Boolean;

implementation

uses
  ComCtrls, Menus, Math, TeCanvas, TeeProcs, TeeConst, TeeTranslate;

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

Function TeeAskLanguage:Boolean;
begin
  result:=False;

  with TAskLanguage.Create(nil) do
  try
    if ShowModal=mrOk then
       result:=True;
  finally
    Free;
  end;
end;

procedure TAskLanguage.FormCreate(Sender: TObject);
var t : Integer;
    i : Integer;
begin
  BorderStyle:=TeeBorderStyle;

  TeeTranslateControl(Self);

  { remove the item number, set to Objects[] array }
  with LBLangs do
  for t:=0 to Items.Count-1 do
  begin
    i:=Pos(',',Items[t]);
    if i>0 then
    begin
      Items.Objects[t]:=TObject(StrToInt(Copy(Items[t],i+1,255)));
      Items[t]:=Copy(Items[t],1,i-1);
    end;
  end;

  i:=TeeLanguageRegistry;

  { find language in list }
  LBLangs.ItemIndex:=-1;

  with LBLangs do
  for t:=0 to Items.Count-1 do
  if Integer(Items.Objects[t])=i then
  begin
    ItemIndex:=t;
    break;
  end;

  { not found, select default English language }
  if LBLangs.ItemIndex=-1 then
     if LBLangs.Items.Count>0 then
        LBLangs.ItemIndex:=0; { default = English }
end;

procedure TAskLanguage.OKBtnClick(Sender: TObject);
begin
  TeeLanguageSaveRegistry(Integer(LBLangs.Items.Objects[LBLangs.ItemIndex]));
end;

procedure TAskLanguage.LBLangsDblClick(Sender: TObject);
begin
  OKBtnClick(Self);
  ModalResult:=mrOk;
end;

end.
