teetranslate.pas

来自「Delphi TeeChartPro.6.01的源代码」· PAS 代码 · 共 698 行 · 第 1/2 页

PAS
698
字号
         s2:=TeeLanguage.Strings[tt];
         i:=Pos('=',s2);
         if i>0 then s2:=Copy(s2,1,i-1);
         if s=s2 then Inc(Num);
       end;

       if Num>1 then Missing.Add(s+'   ('+IntToStr(Num)+')');
     end;
     Missing.Add('---------------');
   end;
 end;

 Procedure CheckHelpContext(AControl:TWinControl);

   Function GetTextToOutput(C:TControl):String;
   var tmp : TControl;
   begin
     tmp:=C.Parent;
     if not (tmp is TCustomForm) then
        while Assigned(tmp.Parent) do
        begin
          tmp:=tmp.Parent;
          if tmp is TCustomForm then break;
        end;

     result:=C.Name+#9+C.ClassName+#9+#9+tmp.ClassName;
   end;

   Procedure CheckHelpInList(C:TControl; Num:Integer);
   var s:String;
       tmp:String;
       t:Integer;
   begin
     tmp:=IntToStr(Num);
     for t:=0 to HelpIDList.Count-1 do
         if Trim(HelpIDList.ValueFromIndex[t])=tmp then exit;

     S:='BAD: '+GetTextToOutput(C);
     if MissingHelp.IndexOf(S)=-1 then
        MissingHelp.Add(S);
   end;

 var t : Integer;
     S : String;
     tmpHelp : Integer;
 begin
   with AControl do
   for t:=0 to ControlCount-1 do
      if Controls[t] is TWinControl then
      begin
         if TWinControl(Controls[t]).HelpContext=0 then { Missing Help Context number }
         begin
           if TWinControl(Controls[t]).Visible then
           if not (Controls[t] is TPanel) then
               if (Controls[t] is TButton) and (TButton(Controls[t]).Caption='OK') then
               else
               if (Controls[t] is TBitBtn) and (TBitBtn(Controls[t]).Caption='OK') then
               else
               if (Controls[t] is TButton) and (TButton(Controls[t]).Caption='Cancel') then
               else
               if (Controls[t] is TBitBtn) and (TBitBtn(Controls[t]).Caption='Cancel') then
               else
               if (Controls[t] is TRadioGroup) then
               else
               if (Controls[t] is TTabSheet) then
               else
               if (Controls[t] is TGroupBox) then
               else
               if (Controls[t].ClassName='TGroupButton') then
               else
               if (Controls[t].ClassName='TGalleryChart') then
               else
               if (Controls[t] is TPageControl) then
               else
               if (Controls[t] is TCustomForm) then
               else
               begin
                 S:=GetTextToOutput(Controls[t]);
                 if MissingHelp.IndexOf(S)=-1 then
                    MissingHelp.Add(S);
               end;
         end
         else
         begin
           tmpHelp:=TWinControl(Controls[t]).HelpContext;
           CheckHelpInList(Controls[t],tmpHelp);
           MaxHelpContext:=Math.Max(MaxHelpContext,tmpHelp);
         end;

         CheckHelpContext(Controls[t] as TWinControl);
      end
      else
      if Controls[t] is TLabel then
         if TLabel(Controls[t]).HelpContext<>0 then
              MissingHelp.Add('Wrong TLabel helpcontext (Delphi 4) '+GetTextToOutput(Controls[t]));

  end;
  {$ENDIF}

var t          : Integer;
    tt         : Integer;
    tmp        : Integer;
    s          : String;
    HotKeyList : String;
begin
  {$IFDEF TEEFINDMISSING}
  { internal use }
  CheckDuplicates;

  if Assigned(Missing) and (AControl is TWinControl) then
     CheckHelpContext(AControl as TWinControl);
  {$ENDIF}

  if Assigned(TeeLanguage)
     {$IFDEF TEEFINDMISSING}or Assigned(Extract){$ENDIF} then
  begin

    with TControlAccess(AControl) do
    begin
      {$IFDEF TEEFINDMISSING}
      CheckExtract(AControl,TControlAccess(AControl).Caption);
      {$ENDIF}
      s:=Caption;
      if TeeCanTranslate(s,HotKeyList) then Caption:=s;
    end;

    with AControl do
    for t:=0 to ComponentCount-1 do
    begin { traverse all Components, not only Controls }

      if Components[t] is TLabel then
      with TLabel(Components[t]) do
      begin
        {$IFDEF TEEFINDMISSING}
        CheckExtract(AControl.Components[t],Caption);
        {$ENDIF}
        s:=Caption;
        if TeeCanTranslate(s,HotKeyList) then
        begin
          Caption:=s;
          AutoSize:=True;
        end;
      end
      else
      if Components[t] is TComboBox then
      with TComboBox(Components[t]) do
      begin
        tmp:=ItemIndex;
        for tt:=0 to Items.Count-1 do
        begin
          {$IFDEF TEEFINDMISSING}
          CheckExtract(AControl.Components[t],Items[tt]);
          {$ENDIF}
          s:=Items[tt];
          if TeeCanTranslate(s,HotKeyList) then Items[tt]:=s;
        end;
        if ItemIndex<>tmp then ItemIndex:=tmp;
      end
      else
      if Components[t] is TListBox then
      with TListBox(Components[t]) do
      begin
        tmp:=ItemIndex;
        for tt:=0 to Items.Count-1 do
        begin
          {$IFDEF TEEFINDMISSING}
          CheckExtract(AControl.Components[t],Items[tt]);
          {$ENDIF}
          s:=Items[tt];
          if TeeCanTranslate(s,HotKeyList) then Items[tt]:=s;
        end;
        if ItemIndex<>tmp then ItemIndex:=tmp;
      end
      else
      if Components[t] is TRadioGroup then
      with TRadioGroup(Components[t]) do
      begin
        {$IFDEF TEEFINDMISSING}
        CheckExtract(AControl.Components[t],Caption);
        {$ENDIF}
        s:=Caption;
        if TeeCanTranslate(s,HotKeyList) then Caption:=s;
        for tt:=0 to Items.Count-1 do
        begin
          {$IFDEF TEEFINDMISSING}
          CheckExtract(AControl.Components[t],Items[tt]);
          {$ENDIF}
          s:=Items[tt];
          if TeeCanTranslate(s,HotKeyList) then Items[tt]:=s;
        end;
      end
      else
      if Components[t] is TPageControl then
      with TPageControl(Components[t]) do
      begin
        for tt:=0 to PageCount-1 do
        begin
          {$IFDEF TEEFINDMISSING}
          CheckExtract(AControl.Components[t],TTabSheet(Pages[tt]).Caption);
          {$ENDIF}
          s:=TTabSheet(Pages[tt]).Caption;
          if TeeCanTranslate(s,HotKeyList) then TTabSheet(Pages[tt]).Caption:=s;
        end;
      end
      else
      if Components[t] is TTabControl then
      with TTabControl(Components[t]) do
      begin
        for tt:=0 to Tabs.Count-1 do
        begin
          {$IFDEF TEEFINDMISSING}
          CheckExtract(AControl.Components[t],Tabs[tt]{$IFDEF CLX}.Caption{$ENDIF});
          {$ENDIF}
          s:=Tabs[tt]{$IFDEF CLX}.Caption{$ENDIF};
          if TeeCanTranslate(s,HotKeyList) then
             Tabs[tt]{$IFDEF CLX}.Caption{$ENDIF}:=s;
        end;
      end
      else
      if Components[t] is TMenuItem then
      with TMenuItem(Components[t]) do
      begin
        {$IFDEF TEEFINDMISSING}
        CheckExtract(AControl.Components[t],Caption);
        {$ENDIF}
        s:=Caption;
        if TeeCanTranslate(s,HotKeyList) then Caption:=s;
      end
      else
      { last option: TControl }
      if Components[t] is TControl then
      with TControlAccess(Components[t]) do
      begin
        {$IFDEF TEEFINDMISSING}
        CheckExtract(AControl.Components[t],Caption);
        {$ENDIF}
        s:=Caption;
        if TeeCanTranslate(s,HotKeyList) then Caption:=s;
      end;

      { Hints... }
      if AControl.Components[t] is TControl then
      with TControl(AControl.Components[t]) do
      begin
        {$IFDEF TEEFINDMISSING}
        if Hint<>'' then CheckExtract(AControl.Components[t],Hint);
        {$ENDIF}
        s:=Hint;
        if (s<>'') and TeeCanTranslate(s,HotKeyList) then Hint:=s;
      end;
    end;
  end;
end;

Const
  TeeRegistry_Language='Language'; { <-- do not translate }

Function TeeLanguageRegistry:Integer;
begin
  {$IFDEF LINUX}
  with TIniFile.Create(ExpandFileName('~/.teechart')) do
  try
    result:=ReadInteger('Editor',TeeRegistry_Language,-1);
  {$ELSE}
  result:=-1;
  With TRegistry.Create do
  try
    if OpenKey(TeeMsg_EditorKey,False) and
       ValueExists(TeeRegistry_Language) then
          result:=ReadInteger(TeeRegistry_Language);
  {$ENDIF}
  finally
    Free;
  end;
end;

Procedure TeeLanguageSaveRegistry(LanguageNum:Integer);
begin
  {$IFDEF LINUX}
  with TIniFile.Create(ExpandFileName('~/.teechart')) do
  try
    WriteInteger('Editor',TeeRegistry_Language,LanguageNum);
  {$ELSE}
  With TRegistry.Create do
  try
    if OpenKey(TeeMsg_EditorKey,True) then
       WriteInteger(TeeRegistry_Language,LanguageNum);
  {$ENDIF}
  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
  { store selected language in registry }
  TeeLanguageSaveRegistry(Integer(LBLangs.Items.Objects[LBLangs.ItemIndex]));
end;

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

initialization
  TeeProcs.TeeTranslateHook:=TeeTranslate.TeeTranslateControl;
finalization
  TeeProcs.TeeTranslateHook:=nil;
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?