多国语言开发 用程序通过WORD的宏命令实现简繁转换 昨天在搜寻多国语言开发帖子时,发现有人通过DELPHI将简体词组或简单句子通过WORD的宏命令转换成繁体再传回DELPHI,当时没太留意,现在急需,有哪位大虾,有原代码,请赐教,应该不是很长,10-20行左右,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to: leilu() 是呀,还有WORD的繁简转换的宏命令是什么 sMacro := '[CreateGroup(' + sGroupDesc + ',' + sGroupName + ')]'; StrPCopy(szMacro, sMacro); // 转成 Null-Term. 字串 DdeClientConv1.ExecuteMacro(szMacro, False); // 执行宏指令 to: IORILI(眼镜@_@) 老兄,能给个完整的代码吗,我是新手,不太熟悉DELPHI和WORD的接口,谢谢 多国语言界面的实现 New一个Application,project1;然后放了一个菜单,一个按钮一个label,在菜单的第一项中填下了caption=CJ,name=mnuChinese;另一项中填下了 caption=Energy,name=mnuEnglish; 把Demos\Richedit\reinit.pas往己project目录一拷,在 project中又把它加了进来, 按意思先设置一下需要的语言页常数。 implementation uses reinit; const ENGLISH = (SUBLANG_ENGLISH_UK shl 10) or LANG_ENGLISH; CHINESE = (SUBLANG_CHINESE_SIMPLIFIED shl 10) or LANG_CHINESE; {$R *.DFM} 做个初始化 procedure TForm1.FormCreate(Sender: TObject); begin mnuEnglish.Tag:=ENGLISH; mnuChinese.Tag:=CHINESE; end; 然后嘛(不就是菜单切换嘛) 于是把两了菜单都指到了一个地方 procedure TForm1.mnuLangClick(Sender: TObject); begin if LoadNewResourceModule(TComponent(Sender).Tag) <> 0 then ReinitializeForms; end; 呵呵;(90% over) 不会吧,让你step,你到现在都没说,就这么尽抄袭代码。Energy委屈的说,谁让 他是课代表的。想起当年是班里总课代表,我不做功课居然就没人做的年月,不禁 又是一阵感慨。 兄弟们还差10%,加油啊! 菜单[Project]-[Languages]-[Add...] [Next>],选择中文(chs),英语(eng);(我只用了这两种语言); [Next>],[Next>],[Next>],[Finsih],[Yes] 让你保存dpg时小心目录可能是chs,应该用上一级目录才好。 看到了吗,这是你可以修改所有的东西。别乱改。 其中有一些出错信息之类这里都后,放心改好了,改完后可以作为一个模板文件保留。 下次就不用改了。 请关闭吧! 现在可以看到你的project Manager中有3个项目,project1.exe,porject1.eng,project1.chs 后面两了是资源文件,你可以 1,双击project1.eng -- form1,然后修改一些东西。比如button1的caption="eng";改变一下它 的大小和字体。 2,双击project1.chs -- form1,然后修改一些东西。比如button1的caption="chs";改一下字体。 不过最好不要随意改动form的大小和位置! 选中project1.exe,设定为Activate; 然后(兄弟们99%了) 右键project1.chs--build; 右键project1.eng--build; 右键project1.exe--build; run 噫,你会发现exe中的界面不起作用了。呵呵,系统自己自动选择了一个语言页嘛。 什么你不要自动,$#$%^%^&,[project]-[Languages]-[set Active]; 对了如果要在调出那个grid方式修改的工具可以[view]-[Translation Manager]; 好了好了,顺便付上我写了说明的reinit.pas文件其实好好看一下就知道还有更强大 的功能等着你利用呢! 语言页的常数在windows.pas里开始于行218;且 +-----------------------+-------------------------+ | Sublanguage ID | Primary Language ID | +-----------------------+-------------------------+ 15 10 9 0 bit unit ReInit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms; procedure ReinitializeForms; //重新设置form function LoadNewResourceModule(Locale: LCID): Longint; // 调取新的语言资源 implementation type TAsInheritedReader = class(TReader) public procedure ReadPrefix(var Flags: TFilerFlags; var AChildPos: Integer); override; end; procedure TAsInheritedReader.ReadPrefix(var Flags: TFilerFlags; var AChildPos: Integer); begin inherited ReadPrefix(Flags, AChildPos); Include(Flags, ffInherited); end; // 刷新语言页 function SetResourceHInstance(NewInstance: Longint): Longint; var CurModule: PLibModule; begin CurModule := LibModuleList; // 系统全局变量;模块列表。 Result := 0; while CurModule <> nil do begin if CurModule.Instance = HInstance then begin if CurModule.ResInstance <> CurModule.Instance then FreeLibrary(CurModule.ResInstance); // 释放旧语言页所占资源 CurModule.ResInstance := NewInstance; // 设置新语言页 Result := NewInstance; Exit; end; CurModule := CurModule.Next; end; end; // 调取新的语言资源 LCID为语言页; function LoadNewResourceModule(Locale: LCID): Longint; var FileName: array [0..260] of char; P: PChar; LocaleName: array[0..4] of Char; NewInst: Longint; begin GetModuleFileName(HInstance, FileName, SizeOf(FileName)); // 别紧张,只是取一下当前 // 的模块名,之所以如此是 // 由于可能本身是个dll。 GetLocaleInfo(Locale, LOCALE_SABBREVLANGNAME, LocaleName, SizeOf(LocaleName)); //取当前使的语言页 P := PChar(@FileName) + lstrlen(FileName); //指针运算而已 //可能是exe :-) while (P^ <> '.') and (P <> @FileName) do Dec(P); //找到语言页资源文件的后缀 NewInst := 0; Result := 0; if P <> @FileName then // 如果找到 begin Inc(P); if LocaleName[0] <> #0 then begin // Then look for a potential language/country translation lstrcpy(P, LocaleName); // 解出资源文件名文件 NewInst := LoadLibraryEx(FileName, 0, LOAD_LIBRARY_AS_DATAFILE); // 加载资源文件 if NewInst = 0 then begin // Finally look for a language only translation // 加载失败,使用原文件 LocaleName[2] := #0; lstrcpy(P, LocaleName); NewInst := LoadLibraryEx(FileName, 0, LOAD_LIBRARY_AS_DATAFILE); end; end; end; if NewInst <> 0 then Result := SetResourceHInstance(NewInst) // 用资源文件刷语言。 end; function InternalReloadComponentRes(const ResName: string; HInst: THandle; var Instance: TComponent): Boolean; var HRsrc: THandle; ResStream: TResourceStream; AsInheritedReader: TAsInheritedReader; begin { avoid possible EResNotFound exception } if HInst = 0 then HInst := HInstance; HRsrc := FindResource(HInst, PChar(ResName), RT_RCDATA); Result := HRsrc <> 0; if not Result then Exit; ResStream := TResourceStream.Create(HInst, ResName, RT_RCDATA); try AsInheritedReader := TAsInheritedReader.Create(ResStream, 4096); try Instance := AsInheritedReader.ReadRootComponent(Instance); finally AsInheritedReader.Free; end; finally ResStream.Free; end; Result := True; end; function ReloadInheritedComponent(Instance: TComponent; RootAncestor: TClass): Boolean; function InitComponent(ClassType: TClass): Boolean; begin Result := False; if (ClassType = TComponent) or (ClassType = RootAncestor) then Exit; Result := InitComponent(ClassType.ClassParent); Result := InternalReloadComponentRes(ClassType.ClassName, FindResourceHInstance( FindClassHInstance(ClassType)), Instance) or Result; end; begin Result := InitComponent(Instance.ClassType); end; //重新设置在显示中的所有from,; procedure ReinitializeForms; var Count: Integer; I: Integer; Form: TForm; begin Count := Screen.FormCount; for I := 0 to Count - 1 do begin Form := Screen.Forms[I]; ReloadInheritedComponent(Form, TForm); //重新刷新所有元件几其父对象 end; end; end. 我知道Delphi7提供一个kcharset.pas的文件,function FKGB2132ToBigFive(vString: string): string;这个函数功能是简体与繁体的转换. to: yzykjh(爱吃子姜的人) 我的DELPHI7 不认这个函数,怎么办 //Delphi6+Word2000测试通过~~uses Word2000;procedure TForm1.Button1Click(Sender: TObject);var vTemplate, vNewTemplate, vDocumentType, vVisible: OleVariant; FileName: OleVariant; FileFormat: OleVariant; LockComments: OleVariant; Password: OleVariant; AddToRecentFiles: OleVariant; WritePassword: OleVariant; ReadOnlyRecommended: OleVariant; EmbedTrueTypeFonts: OleVariant; SaveNativePictureFormat: OleVariant; SaveFormsData: OleVariant; SaveAsAOCELetter: OleVariant;begin TButton(Sender).Enabled := False; with TWordApplication.Create(nil) do try try Connect; except { TODO : 提示错误 } Exit; end; vTemplate := 'c:\temp\t.txt'; vNewTemplate := False; vDocumentType := EmptyParam; vVisible := True; Documents.Add(vTemplate, vNewTemplate, vDocumentType, vVisible); Selection.Range.TCSCConverter(wdTCSCConverterDirectionSCTC, True, True); Visible := True; FileName := 'c:\temp\t~.txt'; FileFormat := wdFormatText; LockComments := False; Password := ''; AddToRecentFiles := True; WritePassword := ''; ReadOnlyRecommended := False; EmbedTrueTypeFonts := False; SaveNativePictureFormat := False; SaveFormsData := False; SaveAsAOCELetter := False; ActiveDocument.SaveAs( FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter); Quit; Disconnect; finally Free; Forms.Application.ProcessMessages; TButton(Sender).Enabled := True; end;end; 我现在也在做这样的东西,有个老法子,把原程序中的所有的汉字和控件的caption都改成繁体后存在一个对应窗体名的ini文件中,写一个函数从ini文件中读,在formshow中运行函数。在google中查‘多语言应用程序’有源程序。 不知谁有什么更好的办法。请告知。[email protected] cxgrid 多列排版 fastreport 中文问题(先给20分、解决后再给80) 在天津工作的delphi程序员,请进,菜鸟有事询问~~~顶着有分!! vc++怎么转到delphi,加油呀! 老生常谈:如何获取IE/Netcape/等浏览器网页内容? 请问怎么获知一个库里面有那些用户表? 求职,要求工作地点广东或厦门 请看以下问题 关于查询是否包含的问题!!! 定义变量Variant,在调试的时候怎么看Variant类型的值? 一个建议,大家进来看看 datetimepicker中为什么只能改变日期,不能更改时间?
是呀,还有WORD的繁简转换的宏命令是什么
StrPCopy(szMacro, sMacro); // 转成 Null-Term. 字串
DdeClientConv1.ExecuteMacro(szMacro, False); // 执行宏指令
老兄,能给个完整的代码吗,我是新手,不太熟悉DELPHI和WORD的接口,谢谢
New一个Application,
project1;然后放了一个菜单,一个按钮一个label,
在菜单的第一项中填下了caption=CJ,name=mnuChinese;
另一项中填下了 caption=Energy,name=mnuEnglish; 把Demos\Richedit\reinit.pas往己project目录一拷,在
project中又把它加了进来, 按意思先设置一下需要的语言页常数。
implementation uses reinit; const
ENGLISH = (SUBLANG_ENGLISH_UK shl 10) or LANG_ENGLISH;
CHINESE = (SUBLANG_CHINESE_SIMPLIFIED shl 10) or LANG_CHINESE; {$R *.DFM} 做个初始化
procedure TForm1.FormCreate(Sender: TObject);
begin
mnuEnglish.Tag:=ENGLISH;
mnuChinese.Tag:=CHINESE;
end;
然后嘛(不就是菜单切换嘛)
于是把两了菜单都指到了一个地方
procedure TForm1.mnuLangClick(Sender: TObject);
begin
if LoadNewResourceModule(TComponent(Sender).Tag) <> 0 then
ReinitializeForms;
end; 呵呵;(90% over) 不会吧,让你step,你到现在都没说,就这么尽抄袭代码。Energy委屈的说,谁让
他是课代表的。想起当年是班里总课代表,我不做功课居然就没人做的年月,不禁
又是一阵感慨。
兄弟们还差10%,加油啊!
菜单[Project]-[Languages]-[Add...]
[Next>],选择中文(chs),英语(eng);(我只用了这两种语言);
[Next>],[Next>],[Next>],[Finsih],[Yes]
让你保存dpg时小心目录可能是chs,应该用上一级目录才好。 看到了吗,这是你可以修改所有的东西。别乱改。
其中有一些出错信息之类这里都后,放心改好了,改完后可以作为一个模板文件保留。
下次就不用改了。
请关闭吧!
现在可以看到你的project Manager中有3个项目,project1.exe,porject1.eng,project1.chs
后面两了是资源文件,你可以
1,双击project1.eng -- form1,然后修改一些东西。比如button1的caption="eng";改变一下它
的大小和字体。
2,双击project1.chs -- form1,然后修改一些东西。比如button1的caption="chs";改一下字体。
不过最好不要随意改动form的大小和位置!
选中project1.exe,设定为Activate; 然后(兄弟们99%了)
右键project1.chs--build;
右键project1.eng--build;
右键project1.exe--build;
run 噫,你会发现exe中的界面不起作用了。呵呵,系统自己自动选择了一个语言页嘛。
什么你不要自动,$#$%^%^&,[project]-[Languages]-[set Active];
对了如果要在调出那个grid方式修改的工具可以[view]-[Translation Manager]; 好了好了,顺便付上我写了说明的reinit.pas文件其实好好看一下就知道还有更强大
的功能等着你利用呢!
语言页的常数在windows.pas里开始于行218;且
+-----------------------+-------------------------+
| Sublanguage ID | Primary Language ID |
+-----------------------+-------------------------+
15 10 9 0 bit unit ReInit; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms; procedure ReinitializeForms; //重新设置form
function LoadNewResourceModule(Locale: LCID): Longint; // 调取新的语言资源 implementation type
TAsInheritedReader = class(TReader)
public
procedure ReadPrefix(var Flags: TFilerFlags; var AChildPos: Integer); override;
end; procedure TAsInheritedReader.ReadPrefix(var Flags: TFilerFlags; var AChildPos: Integer);
begin
inherited ReadPrefix(Flags, AChildPos);
Include(Flags, ffInherited);
end; // 刷新语言页
function SetResourceHInstance(NewInstance: Longint): Longint;
var
CurModule: PLibModule;
begin
CurModule := LibModuleList; // 系统全局变量;模块列表。
Result := 0;
while CurModule <> nil do
begin
if CurModule.Instance = HInstance then
begin
if CurModule.ResInstance <> CurModule.Instance then
FreeLibrary(CurModule.ResInstance); // 释放旧语言页所占资源
CurModule.ResInstance := NewInstance; // 设置新语言页
Result := NewInstance;
Exit;
end;
CurModule := CurModule.Next;
end;
end; // 调取新的语言资源 LCID为语言页;
function LoadNewResourceModule(Locale: LCID): Longint;
var
FileName: array [0..260] of char;
P: PChar;
LocaleName: array[0..4] of Char;
NewInst: Longint;
begin
GetModuleFileName(HInstance, FileName, SizeOf(FileName)); // 别紧张,只是取一下当前
// 的模块名,之所以如此是
// 由于可能本身是个dll。
GetLocaleInfo(Locale, LOCALE_SABBREVLANGNAME, LocaleName, SizeOf(LocaleName)); //取当前使的语言页
P := PChar(@FileName) + lstrlen(FileName); //指针运算而已 //可能是exe :-)
while (P^ <> '.') and (P <> @FileName) do Dec(P); //找到语言页资源文件的后缀
NewInst := 0;
Result := 0;
if P <> @FileName then // 如果找到
begin
Inc(P);
if LocaleName[0] <> #0 then
begin
// Then look for a potential language/country translation
lstrcpy(P, LocaleName); // 解出资源文件名文件
NewInst := LoadLibraryEx(FileName, 0, LOAD_LIBRARY_AS_DATAFILE); // 加载资源文件
if NewInst = 0 then
begin
// Finally look for a language only translation // 加载失败,使用原文件
LocaleName[2] := #0;
lstrcpy(P, LocaleName);
NewInst := LoadLibraryEx(FileName, 0, LOAD_LIBRARY_AS_DATAFILE);
end;
end;
end;
if NewInst <> 0 then
Result := SetResourceHInstance(NewInst) // 用资源文件刷语言。
end; function InternalReloadComponentRes(const ResName: string; HInst: THandle; var Instance: TComponent): Boolean;
var
HRsrc: THandle;
ResStream: TResourceStream;
AsInheritedReader: TAsInheritedReader;
begin { avoid possible EResNotFound exception }
if HInst = 0 then HInst := HInstance;
HRsrc := FindResource(HInst, PChar(ResName), RT_RCDATA);
Result := HRsrc <> 0;
if not Result then Exit;
ResStream := TResourceStream.Create(HInst, ResName, RT_RCDATA);
try
AsInheritedReader := TAsInheritedReader.Create(ResStream, 4096);
try
Instance := AsInheritedReader.ReadRootComponent(Instance);
finally
AsInheritedReader.Free;
end;
finally
ResStream.Free;
end;
Result := True;
end; function ReloadInheritedComponent(Instance: TComponent; RootAncestor: TClass): Boolean; function InitComponent(ClassType: TClass): Boolean;
begin
Result := False;
if (ClassType = TComponent) or (ClassType = RootAncestor) then Exit;
Result := InitComponent(ClassType.ClassParent);
Result := InternalReloadComponentRes(ClassType.ClassName, FindResourceHInstance(
FindClassHInstance(ClassType)), Instance) or Result;
end; begin
Result := InitComponent(Instance.ClassType);
end; //重新设置在显示中的所有from,;
procedure ReinitializeForms;
var
Count: Integer;
I: Integer;
Form: TForm;
begin
Count := Screen.FormCount;
for I := 0 to Count - 1 do
begin
Form := Screen.Forms[I];
ReloadInheritedComponent(Form, TForm); //重新刷新所有元件几其父对象
end;
end; end.
function FKGB2132ToBigFive(vString: string): string;
这个函数功能是简体与繁体的转换.
我的DELPHI7 不认这个函数,怎么办
var
vTemplate, vNewTemplate, vDocumentType, vVisible: OleVariant;
FileName: OleVariant;
FileFormat: OleVariant;
LockComments: OleVariant;
Password: OleVariant;
AddToRecentFiles: OleVariant;
WritePassword: OleVariant;
ReadOnlyRecommended: OleVariant;
EmbedTrueTypeFonts: OleVariant;
SaveNativePictureFormat: OleVariant;
SaveFormsData: OleVariant;
SaveAsAOCELetter: OleVariant;
begin
TButton(Sender).Enabled := False;
with TWordApplication.Create(nil) do try
try
Connect;
except
{ TODO : 提示错误 }
Exit;
end;
vTemplate := 'c:\temp\t.txt';
vNewTemplate := False;
vDocumentType := EmptyParam;
vVisible := True;
Documents.Add(vTemplate, vNewTemplate, vDocumentType, vVisible);
Selection.Range.TCSCConverter(wdTCSCConverterDirectionSCTC, True, True); Visible := True;
FileName := 'c:\temp\t~.txt';
FileFormat := wdFormatText;
LockComments := False;
Password := '';
AddToRecentFiles := True;
WritePassword := '';
ReadOnlyRecommended := False;
EmbedTrueTypeFonts := False;
SaveNativePictureFormat := False;
SaveFormsData := False;
SaveAsAOCELetter := False; ActiveDocument.SaveAs(
FileName,
FileFormat,
LockComments,
Password,
AddToRecentFiles,
WritePassword,
ReadOnlyRecommended,
EmbedTrueTypeFonts,
SaveNativePictureFormat,
SaveFormsData,
SaveAsAOCELetter); Quit;
Disconnect;
finally
Free;
Forms.Application.ProcessMessages;
TButton(Sender).Enabled := True;
end;
end;
在google中查‘多语言应用程序’有源程序。
不知谁有什么更好的办法。请告知。[email protected]