CSDN博客

img danielxuao

如何在同一个工程里添加多种语言

发表于2004/1/20 21:29:00  809人阅读

这应该是一个使用VC的一个小技巧,不过在打算做之前,在网上找了找,没有找到(可能是我填入的关键字不对,:-)),所以在这里给大家提供一个参考,希望对大家能提供方便,不用象我找的这么辛苦。

意图:实现多种语言在同一个工程里,如果调试成功后,即可以同时编译程序的多种语言版本。

平台:Win2000 Pro SP4, VC++6.0,SDK

一般情况下,编写程序都会使用工程制作向导,生成的工程有两个编译版本,一个是Debug,另外一个就是Release,我的目的就是添加多种语言的编译版本,同时需要多种语言的.rc文件(Source文件),然后经过一些简单的设置,就Okay了。

       我添加很多的图片,这样比较容易理解,也少去读文字的痛苦(用电脑看大篇大篇的文字真的很痛苦)。

  下面我们开始:

  1. 首先是以工程文件里的.rc文件为基础,制作多种语言的.rc文件,就是把有关对话框,属性页,以及一些ID文字替换为其他的语言文字,这里需要注意的是,不同语言版本的.rc文件,包含很多相同的图标(Icon),对话框(Dialog),String Table,在VC编译器的SourceView里都要选择相应的语种。比如:如果是English,以上说的这些都要选择English(U.S.)。

 

 

  2. 添加多语言编译版本,选择Build->Configurations,点击Add,添加相应的语言编译版本,我这里添加的是English Release。随后添加多种语言版本。

 

 

 

 

添加多种语言的编译版本

 

 

  3. 编辑不同语言版本的Project Setting。点击菜单Project->Settings,修改相应的设置

设置Output directories: 包括Intermediate和Output files,我这里都设置为English Release

 

 

设置Output file name: 我这里设置为English_Release/ktrexe.exe

 

 

设置Language 英语(美国)    

 

 

 

4. 添加Source Files

 

 

 

 

 

 

 

添加后会弹出一个对话框,不用理会它

 

 

 

 

此时你可以在你编译器的ResourceView里看到:

 

 

 

以后如果需要修改不同的语言,可以修改相应的resources文件。


5. 点击Project->Settings,点击你所点击的.rc文件

 

 

 

 

选中Exclude file from build

 

 

 

 

选择“是”,每一种.rc文件分别选取相应的语言编译版本,比如Win32 English Release,选择Winapp1_English.rc,然后在Exclude file from build打勾即可。

 

6. 编译:

选择Build->Batch Build

 

 

 

 

选中您所要编译的语种,选中Selection only,点击Rebuild All即可。

 

 

 

 

7. 此时,您可以看到您的.dsp文件已经被修改。

 

 

       我曾经在CSDN论坛上问过此问题,还有不同的解法,我把他们帖出来:

 

    我的操作是在VC++6.0里有一个用Win32程序向导生成的一个工程,此工程代码添加,调试,运行都已经Okay

    由于该工程是简体中文的,我想添加其他的语言版本,我就在.rc复本的基础上把简体中文的项目换成了其他的语言(比如西班牙语),然后我在Build->Configurations里添加了Spanish Release,在Project-Settings里设置了语言环境,输入路径等等属性。随后我就在Project-Add Files添加我刚才更换语言的.rc文件添加进来。

    目的是用Debug调试,然后在Build-Batch Build选项里选择我要编译的语言种类,一次编译多种语言。

    问题是VC6.0提示说“Multiple.rc files exist in this project. Only one can be marked as included in the build. The others will be excluded frome the build.

    请问,如何解决这个问题,我在网上找了两天了,在其他的Newsgroups上法帖,没有找到答案,是不是我哪里设置错了,请高手给个提示。谢谢!

 

把你现在的.rc保存,然后把所有的中文换成其他语言,别存为其他other.rc

GetResourceInstance()得到资源句柄。换成另other.rc,(SetResourceHandle)

就可以搞定。

因为所有的id没变, 所有程序都能正常运行。

最好把资源做成dll,LoadResource切换

写成INI也是一个好办法!

 

其他论坛的回答:

Several solutions:
1. Place all your resources into one big. rc file.
2. Exclude the additional rc files from the build and include them by the
resource includes (right mouse click on the resource file in the resource
editor). In this case you have to take care that bitmaps and others are only
included once!
3. Create seperate DLL's for each language and use the corresponding handle
to this DLL when loading resources. Read the docu to AfxSetResourceHandle
when you are using the MFC.

1)      use the "resource includes" menu item in VC C++ 6.0 and include one
resource in the other (i.e. #include "file.rc")  Make sure that there are no
conflicts and each resource is properly marked with the correct language.
Mark the RC file as excluded from the build.  It will get built anyway since
it was included in the main RC.

2)      have separate DLL (i.e. a separate sub-project) for each RC file (the
satellite DLL approach to localization)

If you are unhappy with having separate builds for each language then
you'll have to combine the .rc files with (or without if they doesn't use
same identifiers) the proper LANGUAGE ID #ifdef's. If you don't know
about these, use the Resource editor built into the Environment to create
a new .rc with element variants in several languages. Then open the file
and analyse it.

In VS.NET 2003 click on Build>Configuration Manager
You will find your project. Now it is possible to select New in the combo
"Active Solution Configuration" you can add new settings to the current ones
Debug/Release.
In VS6 click on Build->Configurations. You will find your project displayed
as a tree. Click on Add to add new configurations.
In both caes you will be asked what base configuratin should be copied.

Now you can create different Release modes like German/English/Bavarian and
so on...
For each configuration you can define diffrent rc files to be excluded from
the build. Also you can define different output directories.

The disadvantage is that you always have a complete binary for a language
and you can not switch the language on user request!

 

 

如果有问题,请和我联系:danielxu22@cellink.com.cn

0 0

相关博文

我的热门文章

img
取 消
img