Delphi:如何本地化菜单快捷方式的描述?
有没有办法获得像 Ctrl+Z 这样的快捷方式的本地化描述,以便我得到“Ctrl+Z”,如果应用程序在英语系统上运行,而“Strg+Z”在德语系统上运行?
VCL 函数 ShortCutToText 未国际化。 API 函数 GetKeyNameText 稍好一些,但仍然不完美:如果将德语 XP 的区域设置切换为英语(美国),它仍然会生成德语文本。此外,结果都是大写的,这很难看。
说明:我知道如何用自定义版本替换 ShortCutToText 或 Smkc* 资源字符串。但要使用它,我需要翻译后的字符串。我想从操作系统(或类似的)获取这些。
更新:看起来 Microsoft 希望开发人员自行进行翻译 - 请参阅 将菜单项与加速键关联。引用:
例如,要将 CTRL+O 分配给“文件”菜单上的“打开”命令, 您修改菜单项的标题,使其看起来像这样:
打开\tCtrl+O
菜单编辑器中的菜单项已更新以反映新的标题 当您输入时。
请注意,快捷方式是手动附加到标题的。
Is there a way to get a localized description of a shortcut like Ctrl+Z so that I get "Ctrl+Z" if the app runs on an English system and "Strg+Z" on a German system?
The VCL function ShortCutToText isn't internationalized. The API function GetKeyNameText is a bit better but still not perfect: If one switches the regional settings of a German XP to English (US), it still produces German texts. Besides the results are in CAPITALS which is ugly.
Clarification: I know how I can replace ShortCutToText or the Smkc* resource strings with customized versions. But to use that I need the translated strings. And I would like to get these from the OS (or similar).
Update: It looks like Microsoft expects developers to do the translation on their own - see 2. in Associating a Menu Item with an Accelerator Key. Quote:
For example, to assign CTRL+O to the Open command on the File menu,
you modify the menu item’s caption so that it looks like this:Open\tCtrl+O
The menu item in the Menu editor is updated to reflect the new caption
as you type it.
Note that the shortcut is manually appended to the caption.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ShortCutToText 使用 MenuKeyCaps 数组。这不能直接修改(因为它是在菜单单元的实现中),但是该数组填充了可以使用各种翻译工具进行翻译的资源字符串。
您需要翻译 SmkcCtrl 资源字符串常量,该常量位于 consts.pas 中(取决于您的 Delphi 版本)。
[edit]
或者你可以下载 BigProcHook.pas,我也创建了钩子函数并用你自己的替换它们。然后,您可以编写一个重写,调用常规 ShortCutToText 函数,并将文本“Ctrl”替换为“Strg”(反之亦然),而菜单甚至不知道这一点。
但我只会将此作为最后的手段,因为我认为最好只翻译资源。如果您想使用该挂钩,请下载并包含该单元,然后在任何单元中添加以下代码(如果您愿意,可以添加一个单独的新单元)。
它将用您喜欢的任何文本替换快捷方式文本中的 Ctrl,而无需更改任何其他代码。
ShortCutToText uses the MenuKeyCaps array. This cannot be modified directly (because it is in the implementation of the Menus unit), but the array is filled with resourcestrings which can be translated using various translation tools.
You need to translate the SmkcCtrl resourcestring constant, which is in consts.pas (depending on your Delphi version).
[edit]
Or you can download BigProcHook.pas, which I created too hook functions and replace them by your own. You could then write an override that calls the regular ShortCutToText function and replaces the text 'Ctrl' with 'Strg' (or vice versa) without the menu even knowing it.
But I would use this as a last resort only, because I think it is better to just translate the resource. If you want to use the hook, download and include the unit, and add the following code in any unit (a separate, new unit if you like).
It will replace Ctrl in the shortcut text with whatever text you like, without having to change any other code.
我将回答我自己的问题,以便我有一些可以接受的东西:看起来微软希望开发人员自己进行翻译 - 请参阅 将菜单项与加速键关联。引用:
请注意,快捷方式是手动附加到标题的。
I'll answer my own question so that I have something to accept: It looks like Microsoft expects developers to do the translation on their own - see 2. in Associating a Menu Item with an Accelerator Key. Quote:
Note that the shortcut is manually appended to the caption.