BKN
BKN

Reputation: 85

Facing issue with internationalize MainMenu.xib for Cocoa based Mac OS X Application

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.

Upvotes: 0

Views: 349

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96333

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.

Upvotes: 1

Related Questions