关于三语 (简体、繁体、英语) 切换的尝试

关于三语 (简体、繁体、英语) 切换的尝试
在空白窗体上添加 PopupMenu1, 并添加几个测试用的菜单项, 分别命名为: m1、m2、m3、mCn、mBig、mEn;
激活 mCn 的 OnClick 事件和窗体的 OnCreate 事件.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    m1: TMenuItem;
    m2: TMenuItem;
    m3: TMenuItem;
    mCn: TMenuItem;  //Caption: 简体中文
    mBig: TMenuItem; //Caption: 繁体中文
    mEn: TMenuItem;  //Caption: English
    procedure FormCreate(Sender: TObject);
    procedure mCnClick(Sender: TObject);
  end;

var
  Form1: TForm1;
  LanguageList: TStrings;

implementation

{$R *.dfm}

{转换简体到繁体}
function Cn2Big(CnStr: string): string;
var
  Len: Integer;
begin
  Len := Length(CnStr);
  SetLength(Result, Len);
  LCMapString(GetUserDefaultLCID, LCMAP_TRADITIONAL_CHINESE, PChar(CnStr), Len, PChar(Result), Len);
end;

{建立列表: Name 将是英文菜单, Value 将是简体菜单, 繁体是从简体转换得来}
procedure CreateLanguageList;
begin
  with LanguageList do begin
    Clear;
    Add('Default=默认');
    Add('Fit Width=适宽');
    Add('Fit Height=适高');
  end;
end;

{语言变换}
procedure ChangeLanguageList(LangId: Integer);
var
  i: Integer;
begin
  CreateLanguageList;
  with LanguageList do case LangId of
    0: Exit;
    1: for i := 0 to Count - 1 do Values[Names[i]] := Cn2Big(Values[Names[i]]);
    2: for i := 0 to Count - 1 do Values[Names[i]] := Names[i];
  end;
end;

{初始化菜单}
procedure TForm1.FormCreate(Sender: TObject);
begin
  PopupMenu := PopupMenu1;
  PopupMenu1.AutoHotkeys := maManual;
  mBig.OnClick := mCn.OnClick;
  mEn.OnClick := mCn.OnClick;
  mCn.Tag := 0;
  mBig.Tag := 1;
  mEn.Tag := 2;
  mCn.Click;
end;

procedure TForm1.mCnClick(Sender: TObject);
begin
  ChangeLanguageList(TMenuItem(Sender).Tag);
  m1.Caption := LanguageList.Values['Default'];
  m2.Caption := LanguageList.Values['Fit Width'];
  m3.Caption := LanguageList.Values['Fit Height'];
end;

initialization
  LanguageList := TStringList.Create;
finalization
  LanguageList.Free;

end.


效果图:

关于三语 (简体、繁体、英语) 切换的尝试
posted on 2011-07-14 00:30  万一  阅读(3729)  评论(1)  编辑  收藏
上一篇:常用的CSS表格属性


下一篇:项目: 学生信息录入 计应192第五组西李娟娟