简体   繁体   English

在win32 API应用程序中实现全球化/多语言功能

[英]Implementing Globalization / Multilingual feature in win32 API application

I have developend a window application(Win32 API) in visual C++. 我在visual C ++中开发了一个窗口应用程序(Win32 API)。 I have to add multilingual feature in this application. 我必须在此应用程序中添加多语言功能。 Can any one Pls guide me how to get forward with this task. 任何人都可以指导我如何推进这项任务。

the basics for a multilingual application on Windows is the use of "resources". Windows上多语言应用程序的基础是使用“资源”。 a resource is a chunk appended at the end of your executable, which only contains data, and is formatted in a very specific way in order for Windows to be able to interpret those data. 资源是附加在可执行文件末尾的块,它只包含数据,并以非常特定的方式格式化,以便Windows能够解释这些数据。

in your resources, you can find dialog boxes, string tables, but also version informations (those which are displayed in the properties dialog box of a file in the explorer). 在资源中,您可以找到对话框,字符串表以及版本信息(在资源管理器中文件的属性对话框中显示的信息)。 you can watch the resources of any dll or exe by opening the exe or dll in Visual C++. 您可以通过在Visual C ++中打开exe或dll来查看任何DLL或exe的资源。 when developing an application, you can create a resource (File/New), add it to your project (the same as you when you add a file) and edit the resources (using the resource editor, generally a tab next to the File View in project explorer). 在开发应用程序时,您可以创建资源(文件/新建),将其添加到项目中(与添加文件时相同)并编辑资源(使用资源编辑器,通常是文件视图旁边的选项卡)在项目资源管理器中)。

each resource (dialog, dialog, template, version info, string table, ...) contains a language identifier which you can change. 每个资源(对话框,对话框,模板,版本信息,字符串表,...)包含您可以更改的语言标识符。 you can create the same resource multiple times using different language identifier. 您可以使用不同的语言标识符多次创建相同的资源。 once compiled, when the application is loaded by Windows, it will try to open resources which language are the closer to the Windows UI language. 一旦编译完成,当Windows加载应用程序时,它将尝试打开哪种语言更接近Windows UI语言的资源。

a set of functions is defined in the Windows SDK to make good use of those resources: LoadString, LoadCursor, LoadBitmap, and everything in the resources chapter . Windows SDK中定义了一组函数以充分利用这些资源:LoadString,LoadCursor,LoadBitmap以及资源章节中的所有内容。

Now every time you use a string in your code, put it in a String Table resource and use the LoadString function to retrieve it. 现在每次在代码中使用字符串时,将其放在String Table资源中并使用LoadString函数来检索它。 windows and dialog boxes are generally loaded in the correct language without needing any specific function call, as long as you have set the correct language identifier in the resources. 只要您在资源中设置了正确的语言标识符,窗口和对话框通常以正确的语言加载而无需任何特定的函数调用。

voila, that's the shortest introduction to multilingual development under Windows that i could do. 瞧,这是我能在Windows下进行多语种开发的最短内容。 i am sure that you can find a lot of well-written articles about resources or multilingual development under Windows on the net. 我相信你可以在网上找到很多关于资源或多语言开发的精心撰写的文章。

There are several sides you have to worry about: 您有几个方面需要担心:

  1. Compile your application as Unicode 将您的应用程序编译为Unicode
  2. localizing (translating) the application, making it "speak" another language 本地化(翻译)应用程序,使其“说”另一种语言
  3. use locale-aware behavior, where you have to sort, or format date/time/numbers as expected by the user 使用区域设置感知行为,您必须按照用户的预期排序或格式化日期/时间/数字

For localization the best current practice is to no use strings in your code, but store them in resource-only DLLs (or "satellite DLL") Probably best to start from here: http://msdn.microsoft.com/en-us/goglobal/bb978454.aspx , especially the tutorials and presentations on the right. 对于本地化,最好的当前做法是在代码中不使用字符串,但将它们存储在仅资源的DLL(或“附属DLL”)中可能最好从这里开始: http//msdn.microsoft.com/en-us /goglobal/bb978454.aspx ,特别是右边的教程和演示文稿。

For the localization work down to detail, you can check this: http://mihai-nita.net/2007/05/03/how-to-localize-an-rc-file/ 有关详细的本地化工作,您可以查看: http//mihai-nita.net/2007/05/03/how-to-localize-an-rc-file/

For locale-aware behavior you have to use special APIs like GetNumberFormat or GetDateFormat. 对于区域设置感知行为,您必须使用特殊API,如GetNumberFormat或GetDateFormat。 You can probably start from here http://msdn.microsoft.com/en-us/library/dd319078%28VS.85%29.aspx or here http://msdn.microsoft.com/en-us/goglobal/dd565826.aspx 你可以从这里开始http://msdn.microsoft.com/en-us/library/dd319078%28VS.85%29.aspx或这里http://msdn.microsoft.com/en-us/goglobal/dd565826的.aspx

But of course no answer here will be enough, since there are full books on the topic. 但是当然没有答案就足够了,因为有关于这个主题的完整书籍。 So just start from the MS globalization portal ( http://msdn.microsoft.com/en-us/goglobal/ ), especially the "Learn" tab, and o from there. 所以,从MS全球化门户网站( http://msdn.microsoft.com/en-us/goglobal/ )开始,特别是“学习”选项卡,以及o。

And when you bump into some troubles (you most likely will), stop by at the microsoft.public.win32.programmer.international newsgroup (I know, taking someone away from stackoverflow might not be "good form", but there is a dedicated place, so you might get better answers). 当你碰到一些麻烦(你很可能会遇到)时,请在microsoft.public.win32.programmer.international新闻组停下来(我知道,让某人远离stackoverflow可能不是“好形式”,但有一个专门的地方,所以你可能会得到更好的答案)。

对所有字符串使用gettext。

This can be a big problem, or a small problem, depending on what your program does. 可能是一个大问题, 可能是一个小问题,具体取决于您的程序。

Things to look into: 要研究的事情:

  1. String and character encoding. 字符串和字符编码。 Putting strings into a resource (or using gettext) is a start, but you may want to consider how you store strings internally; 将字符串放入资源(或使用gettext)是一个开始,但您可能想要考虑如何在内部存储字符串; eg. 例如。 look into a Unicode encoding like UTF-16 if you aren't using such an encoding already. 如果你没有使用这样的编码,请查看像UTF-16这样的Unicode编码。

  2. Consider how you process and store string data, as it matters as well: do you need to sort or do case comparisons? 考虑如何处理和存储字符串数据,因为它也很重要:您需要排序或进行案例比较吗? ASCII order (eg comparing the simple value in a 'char') might not be right. ASCII顺序(例如比较'char'中的简单值)可能不正确。 Some of these concerns are outlined here . 这里概述其中一些问题。

  3. Date and time output formats, money output formats, and other things depend on culture as well. 日期和时间输出格式,货币输出格式以及其他依赖于文化的东西。

  4. Finally, it's possible that you may need to re-layout your UI elements depending on what interface technology you are using. 最后,您可能需要根据所使用的接口技术重新布局UI元素。 Strings are longer and shorter in different laguages with different system fonts. 使用不同系统字体的不同语言中的字符串越来越短。 In the extreme case, you may need to consider your layout for right-to-left readers. 在极端情况下,您可能需要考虑从右到左读者的布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM