Java教程

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

本文主要是介绍关于三语 (简体、繁体、英语) 切换的尝试,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
关于三语 (简体、繁体、英语) 切换的尝试
在空白窗体上添加 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.


效果图:

o_20110714.png
posted on 2011-07-14 00:30  万一  阅读(3729)  评论(1)  编辑  收藏
这篇关于关于三语 (简体、繁体、英语) 切换的尝试的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!