VC ++ 10 MFC:执行本地化的正确方法是什么 [英] VC++ 10 MFC: What is the correct way to do localization

查看:130
本文介绍了VC ++ 10 MFC:执行本地化的正确方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个.NET专家,他必须在MFC应用程序上做一些工作.该应用程序是我已转换为VS2010的VS2008 MFC可执行文件.原始开发人员通过在应用程序命令行上指定带有键值对的.txt文件的名称来进行本地化.可执行文件的已安装快捷方式将根据应用程序所在的国家/地区指定一个不同的.txt文件.如果您直接运行.exe,这当然是行不通的.这似乎是对我做事的怪异方法.

我想通过适当的MFC方式执行此操作,但是我很难在Google上找到明确的答案.我的理解是.rc文件中的字符串表应用于此本地化吗?这是MFC当前的最佳做法吗?

关于字符串表,我已经读过,这种做法是针对每个不同的语言创建多个字符串表. MFC应用程序如何选择要使用的语言?是基于计算机当前的语言设置还是我可以控制它(可能是我们希望由我们也在构建的Wix .msi安装程序指定该语言)?

我还读到将所有资源都嵌入MFC应用程序中已不再受欢迎,现在您应该编译单独的资源.dlls吗?这是真的病了,要研究如何做...

最后,我是否需要做一些特殊的事情才能使MFC支持Unicode或默认情况下是MFC Unicode?

谢谢

解决方案

想法是所有可本地化的项目都应存储在资源中.标准UI对象(例如菜单和对话框)会自动存储在其中(资源),但是诸如字符串文字(例如:错误消息,消息框提示等)的项目应从源代码中拉到字符串表中.我的这段 codeproject文章演示了如何轻松地从字符串表中提取字符串您的代码.

注意:资源脚本(.rc)中应该只有一个字符串表.

从那里开始,您可以转换资源并创建资源DLL(又名附属DLL).想法是为每种语言保留.rc文件的不同副本.每个翻译都被编译成一个无代码 DLL,该DLL充当资源的容器.

我的另一篇代码项目文章使您可以轻松地根据系统设置或用户首选项:代码在资源DLL中查找,这些DLL的可用语言与用户设置最匹配(基于用户的UI语言和区域设置).该代码还使您可以轻松构建具有所有可用语言的菜单.这样,您的用户可以覆盖默认选项.

免责声明:我的广告跟随.随时跳过:-)

关于资源的翻译,翻译的管理和资源DLL的创建,您可能需要查看 appTranslator .

广告结束:-)

关于Unicode,MFC附带了ANSI和Unicode版本的代码.由您决定要构建ANSI还是Unicode应用程序:只需在项目设置的第一页中进行选择.当然,如果您是从头开始的,则绝对应该使用Unicode.但是,如果出于传统原因迫使您保留ANSI/MBCS,则不必担心:它不会阻止您对应用程序进行本地化.

I am a .NET guy who is having to do some work on an MFC app. The app is a VS2008 MFC executable which I have converted to VS2010. The original developers did localisation by specifying the name of a .txt file with key value pairs in it on the applications command line. Installed shortcuts to the executable specify a different .txt file depending on which country the app is being installed in. This of course does not work if you just run the .exe directly. This seems like a weird way to do things to me.

I want to do this the propper MFC way, but I am having difficulty finding definitive answers on Google. My understanding is that the String Table in the .rc file should be used for this localisation? Is this the current best practice for MFC?

With respect to the String Table I have read that the practice is to create multiple string tables each for a different language. How do MFC applications choose which language to use? Is it based on the machines current language settings or can I control this (it may be that we want the language to be specified by the Wix .msi installer we are also building)?

I have also read that embedding all resource inside an MFC application has fallen out of favor and that now you should compile seperate resource .dlls? Is this is true ill investigate how to do it...

Finally, do I have to do something special to get MFC to support Unicode or is MFC Unicode by default?

Thanks

解决方案

The idea is that all localizable items should be stored in resources. Standard UI objects such as menus and dialogs are automatically stored in there (resources) for you but items such as string literals (eg: error messages, messagebox prompts,...) should be pulled from source code to the string table. This short codeproject article of mine demonstrates how to easily pull strings from the string table in your code.

Note: You should have only one string table in your resource script (.rc).

From there on, you can translate your resources and create resource DLLs (aka satellite DLLs). The idea is that you keep a different copy of the .rc file(s) for each language. Each translation is compiled into a codeless DLL that acts as a container for the resources.

This other codeproject article of mine lets you easily load resource DLLs according to system settings or user preferences: The code looks among your resource DLLs which available language best matches user settings (based on user's UI language and regional settings). The code also lets you easily build a menu with all available languages. That way, your user can override the default choice.

DISCLAIMER: My ad follows. Feel free to skip :-)

Regarding the translation of resources, the management of translations and the creation of resource DLLs, you may want to check out appTranslator.

END OF AD :-)

Regarding Unicode, MFC ships with ANSI and Unicode versions of the code. It's up to you to choose if you want to build an ANSI or a Unicode app: Just make your pick in the first page of project settings. Of course, if you are startgin from scratch, you should definitely go Unicode. But if legacy reasons force you to stay ANSI/MBCS, don't worry to much: It won't prevent you from localizing your app.

这篇关于VC ++ 10 MFC:执行本地化的正确方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆