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

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

问题描述

我是一名 .NET 人员,必须在 MFC 应用程序上做一些工作.该应用程序是一个 VS2008 MFC 可执行文件,我已将其转换为 VS2010.最初的开发人员通过在应用程序命令行中指定包含键值对的 .txt 文件的名称来进行本地化.已安装的可执行文件快捷方式会根据应用程序安装在哪个国家/地区指定不同的 .txt 文件.如果您只是直接运行 .exe,这当然不起作用.这对我来说似乎是一种奇怪的做事方式.

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

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

我还读到,将所有资源嵌入到 MFC 应用程序中已经失宠,现在您应该编译单独的资源 .dll 吗?这是真的吗?我调查一下怎么做...

最后,我必须做一些特别的事情来让 MFC 支持 Unicode 还是 MFC 默认为 Unicode?

谢谢

解决方案

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

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

从那里开始,您可以翻译您的资源并创建资源 DLL(也称为卫星 DLL).这个想法是您为每种语言保留不同的 .rc 文件副本.每个翻译都被编译成一个无代码 DLL,作为资源的容器.

我的其他 codeproject 文章 让您根据系统设置或用户首选项:代码在资源 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天全站免登陆