[译]资源比较器
By robot-v1.0
本文链接 https://www.kyfws.com/applications/resource-comparer-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 10 分钟阅读 - 4677 个词 阅读量 0[译]资源比较器
原文地址:https://www.codeproject.com/Articles/7674/Resource-Comparer
原文作者:PEK
译文由本站 robot-v1.0 翻译
前言
Compares two .RC-files and shows important differences. Useful if you create programs in multiple languages.
比较两个.RC文件并显示出重要差异.如果您使用多种语言创建程序,则很有用.
介绍(Introduction)
我一直在使用Visual C ++中的资源编辑器来创建多种语言的程序.它效果很好,并且非常易于使用.但是要使所有语言保持同步非常困难.例如,如果您升级程序并添加控件,则可能还需要用其他语言添加它.如果您记得这样做,这很容易:-).为了解决这个问题,我创建了一个比较两个资源文件的工具((I have been using the resource editor in Visual C++ for a while to create programs in multiple languages. It works great and is very easy to use. But it is quite hard to keep all languages synchronized. For example, if you upgrade your program and add a control, you will probably need to add it in other languages as well. This is easy, if you remember to do it :-). To solve this, I created a tool that compares two resource-files ().rc(.rc*)*),并注意某些东西是否看起来不正确(例如缺少控件,不同的窗口样式…).(*) and notices if something doesn’t look right (like missing controls, different window styles…).*)
使用程序(Using the program)
RC非常易于使用.选择要比较的两个文件,然后单击"比较".几秒钟后,比较完成,您将看到结果.如果文件中有多种语言的资源,并且只想阅读特定的语言,请在语言框中输入语言字符串(例如(RC is quite straightforward to use. Select the two files you want to compare, and click on Compare. After a couple of seconds is the comparing done and you see the result. If you have resources in multiple languages in a file and just want to read a specific language, write the language string in the language boxes (like) LANG_ENGLISH
对于英语).如果您想阅读所有语言,请将其留空.(for English). Leave this empty if you want to read all languages.)
如果程序无法解析文件,则在窗口底部是错误消息.检测到的语言也可以在这里找到.(In the bottom of the window are error messages if the program fails to parse the files. Detected languages will also be found here.)
该程序的另一个功能是它可以从文件中提取所有字符串.如果要拼写检查程序,这非常有用,只需单击"创建字符串列表",然后将日志复制到字处理器即可.此功能仅使用"文件1".(Another feature of the program is that it could extract all strings from a file. This is very useful if you want to spell check your program, just click on “Make string list” and copy the log to a word processor. Only “File 1” will be used in this function.)
如果要查看"文件1"中的所有资源,请单击"创建资源树".如果取消选中"仅ID",那么您还将看到程序找到的所有设置(如字符串,控件样式).(If you want to see all resources in “File 1”, click on “Make resource tree”. If you uncheck “Only IDs”, then you will also see all settings that the program has found (like strings, style of controls).)
第四个按钮"翻译表"创建一个表,您可以在其中查看字符串的翻译方式.如果您选中" LocalizeRC INI",则输出将被写入为INI文件以用于(The fourth button, “Translation table”, creates a table where you see how strings are translated. If you check “LocalizeRC INI”, the output will be written as an INI-file to use with) 本地化RC(LocalizeRC) (CodeProject上的另一个程序).((another program at CodeProject).)
它检查什么(What it checks)
资源比较器检查以下内容:(Resource Comparer checks these:)
-
选单(Menus)
- 弦乐(Strings)
- 设置(选中,呈灰色…)(Settings (Checked, Grayed…))
- 结构(项目顺序)(Structure (Order of items))
-
工具栏(Toolbars)
- 结构体(Structure)
-
对话方块(Dialogs)
- 字幕(Captions)
- 样式设置(边框,系统菜单…)(Style settings (Border, system menu…))
- 扩展样式设置(工具窗口,客户端…)(Extended style settings (Tool windows, client edge…))
- 制表符顺序(Tab order)
-
控制项(Controls)
- 弦乐(Strings)
- 类型(因此具有相同ID的控件属于同一类型)(Type (So controls with same ID are of the same type))
- 样式设定(Style settings)
- 扩展样式设置(Extended style settings)
- 帮助ID(Help ID)
-
弦乐(Strings)
- %-话(%-words)
- -字符(-characters)
-
位图(Bitmaps)
-
图示(Icons)
-
游标(Cursors) 该程序不检查:(The program does not check:)
-
促进剂(Accelerators)
-
版(Version)
-
组合框中的数据(字符串)(Data (strings) in combo boxes)
-
位图,工具栏,图标或光标的大小.(Size of bitmaps, toolbars, icons or cursors.) **注意:(Note:)**如果您在资源上使用条件设置,则程序将无法解析文件.(The program will fail to parse the file if you are using condition settings on the resources.)
弦乐(Strings)
检查字符串可能非常重要.该程序为您提供了五种使用方法:(Checking strings could be very important. The program gives you five methods to use:)
-
没有(None):(:)不要检查字符串.(Don’t check strings.)
-
**检查%字(Check %-words)**假设您有一个类似这样的字符串:“您的名字是:%s”.您可以将此字符串与(Let’s say you have a string like this: “Your name is: %s”. You use this string with)
CString::Format
用用户名替换"%s".然后,在所有其他语言中,字符串还包括"%s"非常重要.如果不是,那么程序运行时可能会崩溃(to replace “%s” with the user name. Then it is very important that in all other languages, the string also includes “%s”. If it’s not, then your program will probably crash when it runs)CString::Format
.因此,请检查程序所有字符串的%-word数量和顺序是否相同.因此,如果在一个文件中有一个字符串,例如"%s,%d",而在另一个文件中有另一个字符串,例如"%d,%s",则会收到错误消息.(. Therefore, check the program that all strings have the same number and order of %-words. So, if you have a string like “%s, %d” in one file, and another string like “%d, %s” in a second file, then you will get an error message.) -
**检查\字符(Check -characters)**这与(2)非常相似.假设您有一个像这样的字符串:" Hello \ nworld".然后,您将其翻译,并犯了一个小错误:" Hello \ world"(不,它们不相同-请再看一次!).犯这样的错误很容易;我自己做了几次.但是现在,我有了这个程序,如果我再次执行它会警告我:-).(This is very similar to (2). Let’s say you have a string like this: “Hello\nworld”. Then you translate it, and make a little error: “Hello\world” (no, they are not the same - look again!). It is very easy to make mistakes like that; I have done it myself several times. But now, I have this program that will warn me if I do it again :-).)
-
**%-和-问题(%- and - problems)**同时使用测试2和测试3.(Uses both test 2 and test 3.)
-
**比较完整字串(Compare full string)**这将检查字符串是否完全匹配.如果要查看您对旧版本所做的更改,这将很有用.(This checks if strings match completely. This is useful if you want to see what changes you have done from an old version.)
所有字符串都在运行此测试,对话框和菜单中的字符串也在运行.(All strings are running this test, also string in dialogs and menus.)
例(Example)
作为一名程序员,我知道看示例比阅读手册更有趣,所以让我们看一下日志:(As a programmer, I know that it is more interesting to look on an example than reading a manual, so let us look on a log:)
Comparing menus:
Comparing menu resource: IDR_MAINFRAME
Different style in ID: ID_FILE_CHECKED (1: CHECKED, 2: )
Different menu structure. Item 4 is ID_FILE_SAVE in 1,
and ID_FILE_SAVE_AS in 2
Different menu structure. Item 5 is ID_FILE_SAVE_AS in 1,
and ID_FILE_SAVE in 2
Comparing toolbars:
Comparing toolbar resource: IDR_TOOLBAR1
Different toolbar structure. Item 1 is ID_FILE_NEW in 1,
and ID_FILE_SAVE in 2
Different toolbar structure. Item 2 is ID_FILE_SAVE in 1,
and ID_FILE_NEW in 2
Comparing dialogs:
Comparing dialog resource: IDD_ABOUTBOX
String error in IDOK: Different number of %-signs ('OK', 'OK - %s')
Comparing dialog resource: IDD_TEST_DIALOG
Dialog style doesn't match ( DS_MODALFRAME|WS_POPUP|
WS_VISIBLE|WS_CAPTION|WS_SYSMENU,
WS_POPUP|WS_VISIBLE|WS_CAPTION|
WS_SYSMENU|WS_THICKFRAME)
Different style settings on control ID: IDC_LISTCONTROL
(1: 'LVS_REPORT|WS_BORDER|WS_TABSTOP',
2: 'LVS_REPORT|LVS_OWNERDRAWFIXED|
WS_BORDER|WS_TABSTOP')
Couldn't find control ID: IDC_STATIC_EXTRA
Different items count (6 in 1, 5 in 2)
Comparing strings:
String error in IDS_TOFORMAT: Different %-words (%s and %d)
String error in IDS_SLASH: Different number of \-signs
('Hello\r\nworld.', 'Hello\r\\world.')
String error in IDS_ULTRA: Different %-words (%s and %d),
Different \-characters (\r and \n)
Comparing bitmaps:
Couldn't find bitmap: IDB_BITMAP_EXTRA in file 2
Comparing icons:
Couldn't find icon: IDI_ICON_EXTRA in file 2
Comparing cursors:
Couldn't find cursor: IDC_CURSOR_EXTRA in file 2
如您所见,我们已经检查了菜单,工具栏,对话框,字符串,位图,图标和光标.在菜单部分,我们看到在一个文件中,一个菜单项被选中,而在另一个文件中,则没有被选中.两个菜单项也已交换位置.(As you can see, we have checked menus, toolbars, dialogs, strings, bitmaps, icons, and cursors. In the menu section, we see that in one of the files, one menu item is checked, in the other it’s not. Two menu items also have swapped places.)
在工具栏部分中,按钮(In the toolbar section, the buttons) ID_FILE_NEW
和(and) ID_FILE_SAVE
交换了地方.(have swapped places.)
在对话框中,有几个错误.按钮(In the dialogs, there are several errors. The button) IDOK
在about框中的第二个文件中有一个百分号,但在第一个文件中则没有.在另一个对话框中,我们看到该对话框在两个文件中具有不同的样式.该列表在第一个文件中具有"所有者绘制"值,但在第二个文件中没有.我们还在第二个文件中缺少控件,(in the about box has a percent sign in the second file, but in the first, there is none. In the other dialog, we see that the dialog has different styles in the two files. The list has the “Owner draw” value in the first file, but not in the second. We are also missing a control in the second file,) IDC_STATIC_EXTRA
.因此,两个文件中没有相同数量的控件.(. Therefore, we do not have the same number of controls in the two files.)
我们遇到了三个字符串的问题.在(We have problems with three strings. In) IDS_TOFORMAT
,我们在第一个文件中使用"%s",在第二个文件中使用"%d".在字符串中(, we are using “%s” in the first file, and “%d” in the second. In the string) IDS_SLASH
,有一个拼写错误,\应该是\ n.最后,我们有一个同时包含两种错误的字符串.(, there is a misspelling, \ should be \n. In the last, we have a string that has both types of errors.)
我们还看到第二个文件中缺少位图,图标和光标.(We also see that we are missing a bitmap, icon, and a cursor in the second file.)
兴趣点(Points of Interest)
您可以使用一个特殊的ID来拥有多个具有相同ID的项目,(There is a special ID you can use to have multiple number of items with the same ID,) IDC_STATIC
(这是新的静态文本控件的默认ID).当资源比较器比较对话框控件时,它将比较具有相同ID的项目.因此,当多个控件具有相同的ID时,我们就会遇到问题.资源比较器通过使用制表符顺序找出如何匹配控件来解决此问题.与第一个控件((this is the default ID for new static text controls). When Resource Comparer compares dialog controls, it compares items with the same ID. So when more than one control has the same ID, we have a problem. Resource Comparer solves this by using the tab order to figure out how to match the controls. The first control with) IDC_STATIC
将与另一个文件中具有相同ID的第一个控件进行比较.第二个控件将与另一个文件中的第二个控件进行比较,依此类推.(will be compared with the first control with the same ID in the other file. And the second control will be compared with the second control in the other file, and so on.)
如果您看一下代码,您可能会发现我写得很快.但这似乎运作良好,对我来说足够了.解析资源文件是最难的事情.该程序有很多假设,但似乎足够聪明:-).正如我之前所说,条件不受支持.使用条件时(If you look at the code, you may see that I have written it quite fast. But it seems to work well and is enough for me. Parsing the resource files was the hardest thing to do. The program makes a lot of assumptions but it seems to be clever enough :-). As I said before, conditions are not supported. When you use conditions,) #if
语句添加到文件中,我对此并不关心.但是,如果您有兴趣解决这个问题,那就去吧:-).而且我知道输出可能会更好,但是由于我不会经常使用该程序,所以我真的不在乎.(statements are added in the file, and I haven’t cared about this. But if you are interested to solve this problem, just go for it :-). And I know the output could be better, but since I will not use this program very often, I really don’t care about this.)
支持Unicode,但不支持ANSI中的多字节字符.(Unicode is supported, but not multi-byte characters in ANSI.)
我只在VC6中的项目上测试过该程序,但我认为更高版本不会有任何问题.(I have only tested this program on projects made in VC6, but I don’t think there should be any problems with later versions.)
链接和其他(Links and Miscellaneous)
代码项目(CodeProject)
历史(History)
- 2004年8月21日(21 August, 2004)-版本1.2.支持Unicode.应用了Graham Pye的次要修补程序.对话框中的标题现已测试.(- Version 1.2. Support for Unicode. Applied a minor fix by Graham Pye. Captions in dialogs are now tested.)
- 2004年8月4日(4 August, 2004)-版本1.1.现在在控件上选中"帮助ID".具有ID的控件(- Version 1.1. “Help ID” is now checked on controls. Controls with ID)
IDC_STATIC
现在进行比较.如果多个控件具有此ID,则将使用制表符顺序来确定如何匹配它们.该程序现在可以创建INI文件以用于(are now compared. If more than one control has this ID, the tab order will be used to figure out how to match them. The program can now create INI files to use with) RC本地化工具(RC Localization Tool) - 2004年7月10日(10 July, 2004)-初始版本.(- Initial version.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 WinXP Win2003 Windows Win2K Visual-Studio Dev 新闻 翻译