FastCube的多语言化

FastCube 2.10

它的多语言机制没有严格使用ResoureString来处理,如果是那样,直接用Acro Multi-Language Suite元件处理就可以了(Hook了LoadString这个API)。

FastCube的多语言机制是一种静态的字典,类似xml格式,如:

{******************************************}
{                                          }
{                FastCube 2                }
{          Language resource file          }
{                                          }
{         Copyright (c) 2001-2016          }
{     by Oleg Pryalkov, Paul Ishenin,      }
{            Fast Reports Inc.             }
{                                          }
{******************************************}

unit fcxrcStrings;

interface
{$H+}
implementation

uses fcxRes;

const resXML: AnsiString =
'<' + 
'StrRes Name="SDataOverflow" Text="Data overflow error!"/><' + 
'StrRes Name="sInfoFormCaption" Text="Cube information"/>' + 
'' + 
'<' + 
'StrRes Name="sToGrandTotal" Text="Grand Total"/><' + 
'StrRes Name="sExpressionEditor" Text="Expression Editor"/>' + 
' ';

initialization
  fcxResources.AddXML(resXML);

end.

处理字典的机制是在fcxRes.pas文件的TfcxResources类,具体是其Get和GetAnsi两个方法:

  TfcxResources = class(TObject)
  private
    FNames: TStringList;
    FValues: TWideStrings;
    FLanguages: TStringList;
    FHelpFile: String;
    FCP: Cardinal;
    procedure BuildLanguagesList;
  public
    constructor Create;
    destructor Destroy; override;
    function Get(const StrName: String): String;
    function GetAnsi(const StrName: String): String;
    procedure Add(const Ref, Str: String);
    procedure AddW(const Ref: String; Str: WideString);
    procedure AddStrings(const Str: String);
    procedure AddXML(const Str: AnsiString);
    procedure Clear;
    procedure LoadFromFile(const FileName: String);
    procedure LoadFromStream(Stream: TStream);
    procedure Help(Sender: TObject); overload;

    property Languages: TStringList read FLanguages;
    property HelpFile: String read FHelpFile write FHelpFile;
  end;

这种机制,软件要按不同的语言编译成不用的exe发行版。比如早期的windows,分英文版,中文简体版,中文繁体版....后来都不分了,All in one都支持,用户自己选择。

Acro Multi-Language Suite元件就是支持这种All in one的动态切换语言的模式。要适应Fast Cube元件,可以Hook前面说的Get和Get Ansi函数,具体如下:

unit wxhHookRes_FastCube;

interface

implementation
uses
  fcxRes,acroDDetours,acroMultiResource;

type
  TwxhMultiProc_Get=function(const StrName: String): String of Object;
  TwxhMultifcxResources=class(TfcxResources)
  public
    function Get(const StrName: String): String;
    function GetAnsi(const StrName: String): String;
  end;
var
  gOldProc_Get:TMethod;
  gOldProc_GetAnsi:TMethod;

{ TwxhMultifcxResources }

function TwxhMultifcxResources.Get(const StrName: String): String;
begin
  Result:=TwxhMultiProc_Get(gOldProc_Get)(StrName);
  Result:=acroMultiResource.ResourceStorage.GetDisplayValue(Result);
end;

function TwxhMultifcxResources.GetAnsi(const StrName: String): String;
begin
  Result:=TwxhMultiProc_Get(gOldProc_GetAnsi)(StrName);
  Result:=acroMultiResource.ResourceStorage.GetDisplayValue(Result);
end;

initialization
  gOldProc_Get.Data:=fcxRes.fcxResources;
  gOldProc_Get.Code:=acroDDetours.InterceptCreate(@fcxRes.TfcxResources.Get,@TwxhMultifcxResources.Get);
  gOldProc_GetAnsi.Data:=fcxRes.fcxResources;
  gOldProc_GetAnsi.Code:=acroDDetours.InterceptCreate(@fcxRes.TfcxResources.GetAnsi,@TwxhMultifcxResources.GetAnsi);
end.

完美,给张最后效果截图:

FastCube的多语言化_第1张图片

你可能感兴趣的:(delphi开发,delphi多语言套件)