⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teetranslate.pas

📁 TeeChart 7.0 With Source在Delphi 7.0中的安装
💻 PAS
字号:
{**********************************************}
{   Automatic Translation Unit  -Internal-     }
{   Copyright (c) 2001-2005 by David Berneda   }
{**********************************************}
unit TeeTranslate;
{$I TeeDefs.inc}

interface

uses {$IFDEF CLX}
     QGraphics, QForms, QControls, QStdCtrls, QButtons, QExtCtrls,
     {$ELSE}
     Graphics, Forms, Controls, StdCtrls, Buttons, ExtCtrls,
     {$ENDIF}
     SysUtils, Classes;

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

{.$DEFINE TEEFINDMISSING}  { <-- internal use }

{$IFDEF TEEFINDMISSING}
{ internal use }
Procedure StartMissing;
Procedure EndMissing(Const FileName:String);

var Missing:TStringList=nil;
    MissingHelp:TStringList=nil;
    HelpIDList:TStringList=nil;
    MaxHelpContext:Integer=0;

var TeeMissingAddDuplicates:Boolean=False;
    TeeMissingAddUnused:Boolean=False;

Procedure StartExtract;
Procedure EndExtract;

var Extract:TStringList=nil;
{$ENDIF}

Procedure TeeTranslateAControl(AControl:TControl; const ExcludedChilds:Array of TControl);
Function TeeCanTranslate(Var S,HotKeyList:String):Boolean;

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

// Returns the TeeChart Language stored at the IniFile or Registry
Function TeeLanguageRegistry:Integer;

// Stores "Index" TeeChart Language into IniFile or Registry
Procedure TeeLanguageSaveRegistry(LanguageNum:Integer);

type
  {$IFDEF CLR}
  TLanguageStrings=class(TStringList)
  public
    Constructor Create; 
  end;
  {$ELSE}
  TLanguageStrings=TStringList;
  {$ENDIF}

{$IFDEF LCL}
function StripHotkey(const Text: string): string;
{$ENDIF}

implementation

Uses {$IFDEF CLX}
     QComCtrls, QMenus,
     {$ELSE}
     ComCtrls, Menus,
     {$ENDIF}

     Math, TeCanvas, TeeProcs, TeeConst;

{$IFNDEF CLX}
{$IFNDEF LCL}
{$R *.DFM}
{$ENDIF}
{$ELSE}
{$R *.xfm}
{$ENDIF}

{$IFDEF CLR}
Constructor TLanguageStrings.Create;
begin
  inherited;
  LineBreak:=#13;
end;
{$ENDIF}

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

{$IFDEF TEEFINDMISSING}
{ internal use }
Procedure StartMissing;
const ContextEditorFile='f:\kylix\Docs\helpv7\Context_Editor.txt';

var t: Integer;
begin
  Missing:=TStringList.Create;
  MissingHelp:=TStringList.Create;
  HelpIDList:=TStringList.Create;
  if FileExists(ContextEditorFile) then
     HelpIDList.LoadFromFile(ContextEditorFile);
  MaxHelpContext:=0;
  
  if Assigned(TeeLanguage) then
  for t:=0 to TeeLanguage.Count-1 do
      TeeLanguage.Objects[t]:=Pointer(0);
end;

Procedure EndMissing(Const FileName:String);
var t: Integer;
begin
  if TeeMissingAddUnused then
  begin
    Missing.Add('');
    Missing.Add('Unused:');
    Missing.Add('-------');

    if Assigned(TeeLanguage) then
    for t:=0 to TeeLanguage.Count-1 do
        if Integer(TeeLanguage.Objects[t])=0 then
           Missing.Add(TeeLanguage[t]);

    Missing.Add('-------');
  end;

  Missing.SaveToFile(FileName);

  MissingHelp.Add('');
  MissingHelp.Add('Maximum helpcontext = '+IntToStr(MaxHelpContext));
  MissingHelp.SaveToFile('c:\teemissinghelp.txt');

  FreeAndNil(Missing);
  FreeAndNil(MissingHelp);
  FreeAndNil(HelpIDList);
end;

Procedure StartExtract;
begin
  Extract:=TStringList.Create;
end;

Procedure EndExtract;
begin
  Extract.SaveToFile('c:\teeextract.txt');
  Extract.Free;
end;

Function IsNumber(Const S:String):Boolean;
{$IFDEF D6}
var Value : Double;
{$ENDIF}
begin
  {$IFDEF D6}
  result:=TryStrToFloat(S,Value);
  {$ELSE}
  result:=False;
  {$ENDIF}
end;
{$ENDIF}

{$IFNDEF D5}
Const cHotKeyPrefix = '&';
{$ENDIF}

{$IFDEF LCL}
function StripHotkey(const Text: string): string;
var
  I: Integer;
begin
  Result := Text;
  I := 1;
  while I <= Length(Result) do
  begin
    if Result[I] in LeadBytes then
       Inc(I)
    else
    if Result[I] = cHotkeyPrefix then
       Delete(Result, I, 1);
    Inc(I);
  end;
end;
{$ENDIF}

Function TeeCanTranslate(Var S,HotKeyList:String):Boolean;

  {$IFNDEF D5}
  // From Delphi sources. Delphi 4 does not has GetHotKey function.
  function GetHotkey(const Text: string): string;
  var
    I, L: Integer;
  begin
    Result := '';
    I := 1;
    L := Length(Text);
    while I <= L do
    begin
      if Text[I] in LeadBytes then
        Inc(I)
      else if (Text[I] = cHotkeyPrefix) and
              (L - I >= 1) then
      begin
        Inc(I);
        if Text[I] <> cHotkeyPrefix then
          Result := Text[I]; // keep going there may be another one
      end;
      Inc(I);
    end;
  end;
  {$ENDIF}

  // Optimized version of TStringList.Values[].
  Function GetTranslatedString(Const St:String):String;
  var t    : Integer;
      i    : Integer;
      tmpS : string;
  begin
    if Assigned(TeeLanguage) then
    with TeeLanguage do
    for t:=0 to Count-1 do
    begin
      tmpS:=Strings[t];
      i:=Pos('=',tmpS);
      if (i>0) and (Copy(tmpS,1,i-1)=St) then
      begin
        result:=Copy(tmpS,i+1,MaxInt);
        {$IFDEF TEEFINDMISSING}
        Objects[t]:=Pointer(Integer(Objects[t])+1);
        {$ENDIF}
        exit;
      end;
    end;
    result:='';
  end;

  {$IFDEF TEEFINDMISSING}
  Function FoundInLanguage(const s:String):Boolean;
  var t:Integer;
  begin
    with TeeLanguage do
    for t:=0 to Count-1 do
    if Pos('='+s,UpperCase(Strings[t]))>0 then
    begin
      result:=true;
      exit;
    end;
    result:=False;
  end;

  function InTheLanguage(const s:String):Boolean;
  var t:Integer;
  begin
    result:=False;
    exit;

    {$IFDEF D5}
    // pending
    for t:=0 to TeeLanguage.Count-1 do
    if UpperCase(TeeLanguage.ValueFromIndex[t])=s then
    begin
      result:=True;
      exit;
    end;
    result:=False;
    {$ENDIF}
  end;
  {$ENDIF}

var s2         : String;
    s3         : String;
    s4         : String;
    tmpHot     : String;
    HasColon   : Boolean;
    HasHotKey  : Boolean;
    HasEllipse : Boolean;
    t          : Integer;
begin
  result:=False;
  if {$IFDEF TEEFINDMISSING}Assigned(TeeLanguage) and{$ENDIF}
     (s<>'?') and (s<>'%') and (s<>'0') then
  begin
    s:=Trim(s);
    if s<>'' then
    begin
      HasEllipse:=False;
      HasColon:=False;

      { remove hot-key if exists... }
      s4:=StripHotkey(s);
      HasHotKey:=s4<>s;
      if TeeLanguageHotKeyAtEnd and HasHotKey then tmpHot:=GetHotkey(s);

      { ':' }
      s2:=UpperCase(s4);
      if Copy(s2,Length(s2),1)=':' then
      begin
        HasColon:=True;
        s2:=Copy(s2,1,Length(s2)-1);
      end;

      { ... }
      if Copy(s2,Length(s2)-2,3)='...' then
      begin
        HasEllipse:=True;
        s2:=Copy(s2,1,Length(s2)-3);
      end;

      { find new translated string }
      // Optimization of: s3:=TeeLanguage.Values[s2];  { 5.03 }
      s3:=GetTranslatedString(s2);

      if s3<>'' then
      begin
        s:=s3;
        if HasHotKey then { add ampersand (hotkey) to string }
        begin
          if TeeLanguageHotKeyAtEnd then
          begin
            s:=s+'('+cHotKeyPrefix+UpperCase(tmpHot)+')';
          end
          else { default }
          for t:=1 to Length(s) do
          if {$IFDEF CLR}AnsiChar{$ENDIF}(s[t]) in ['a'..'z','A'..'Z','0'..'9'] then
             if Pos(s[t],HotKeyList)=0 then { HotKey char not yet in list }
             begin
               HotKeyList:=HotKeyList+s[t];
               s:=Copy(s,1,t-1)+cHotKeyPrefix+Copy(s,t,Length(s)); { add hotkey }
               break;
             end;
        end;

        { after HotKey, check Ellipse and Colon }
        if HasEllipse then s:=s+'...';
        if HasColon then s:=s+':';
        result:=True;
      end
      else
      begin
       {$IFDEF TEEFINDMISSING}
       // string not found in translation, add to "missing" list...
       if Assigned(Missing) then
          if (s2<>'+') and (s2<>'-') and (s2<>'') and (not IsNumber(s2)) then
             if not FoundInLanguage(s2) then
             begin
               // Tricks:
               if (s2<>UpperCase(TeeMsg_Copyright)) and
                  (s2<>'SERIES 2') and
                  (s2<>'#.#') and
                  (s2<>'0.0%') and
                  (s2<>'DDD

⌨️ 快捷键说明

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