基于 Cocoa 的 Mac OS X 应用程序面临国际化 MainMenu.xib 问题

发布于 2024-12-24 15:49:51 字数 986 浏览 1 评论 0原文

我正在从事一个基于 Cocoa 的 Mac OS X 项目,并面临国际化 MainMenu.xib 的一个问题。

在菜单项中,所有标题都需要以编程方式国际化。除撤消和重做菜单项标题外,所有菜单项(如“剪切”、“复制”、“粘贴”)都可以使用 setTitle 国际化。除此之外,在项目表单的文本字段中输入任何内容后,撤消菜单项标题会动态更改为“撤消键入”。 “重做”也会发生同样的情况。

设置其他菜单的标题和菜单项的标题

[[[[NSApp mainMenu] itemAtIndex:1] submenu]setTitle:@"Edit_Test"] 

我可以使用MainMenu.xib“编辑”菜单

[[[[[NSApp mainMenu] itemAtIndex:1] submenu]itemAtIndex:4]setTitle:@"Copy_Test"] 

,类似地,对于位于“编辑”菜单下的 NSMenuItem“复制”。

但是如果我使用同一段代码,

  [[[[[NSApp mainMenu] itemAtIndex:1] submenu]itemAtIndex:0]setTitle:@"Undo_Test"] 

menuItem标题仍然保留为“Undo”

NSUndoManager提供了方法undoMenuItemTitle和redoMenuItemTitle,但NSUndoManager不会将-setTitle:消息发送到“Undo”和“Redo”菜单项。

那么我怎样才能跟踪标题的动态变化并使“撤消打字”也国际化呢?

是否可以手动获取 MainMenu.xib 的第一响应者并从中获取 undomanager 对象?这样我就可以使用撤消菜单项解除第一响应程序中当前存在的撤消操作的绑定,并手动执行撤消操作,或者是否可以仅以编程方式更改标题而不执行所有这些操作。

如果有人遇到过这个问题并解决了这个问题,请告诉我。

I am working in a Cocoa based Mac OS X project and facing one issue with internationalize MainMenu.xib.

In the menu items, all titles are need to be internationalized programmatically. All the menu items like “cut”, ”copy”, ”paste” can be internationalized using setTitle except the undo and redo menu item title. Adding to this, after typing anything in the text fields of the project forms, the undo menu item title dynamically changed to “Undo Typing”. The same happens for “Redo” also.

I can set the titles of other menu and menuitems' title using,

[[[[NSApp mainMenu] itemAtIndex:1] submenu]setTitle:@"Edit_Test"] 

for MainMenu.xib "Edit" menu and similarly,

[[[[[NSApp mainMenu] itemAtIndex:1] submenu]itemAtIndex:4]setTitle:@"Copy_Test"] 

for NSMenuItem "Copy" which is in under "Edit" menu.

But If I use the same piece of code,

  [[[[[NSApp mainMenu] itemAtIndex:1] submenu]itemAtIndex:0]setTitle:@"Undo_Test"] 

the menuItem title still remain as "Undo"

NSUndoManager provides the methods undoMenuItemTitle and redoMenuItemTitle, but NSUndoManager does not send the -setTitle: messages to the "Undo" and "Redo" menu items.

So how can I track that dynamic change in title and make that "Undo Typing" internationalized also?

Is it possible to manually get the First responder of the MainMenu.xib and from that get the undomanager object? So that i can unbind the undo action that is currently present in the first responder with the undo menu item and perform undo operation manually or is it possible to just change the title programmatically without doing all these.

Please let me know if any one had come across this problem and resolved the issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2024-12-31 15:49:51

创建 NSUndoManager 的子类并覆盖 undoMenuTitleForUndoActionName:方法redoMenuTitleForUndoActionName: 方法。为需要撤消管理器的每个文档(或托管对象上下文或其他事物)创建此子类的实例。

Make a subclass of NSUndoManager and override the undoMenuTitleForUndoActionName: method and the redoMenuTitleForUndoActionName: method. Create instances of this subclass for each document (or managed object context, or other thing) that needs an undo manager.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文