NSUndoManager, NSTextView and exotic localization
NSUndoManager, NSTextView and exotic localization
- Subject: NSUndoManager, NSTextView and exotic localization
- From: email@hidden
- Date: Thu, 22 Jun 2006 16:11:38 +0200 (CEST)
- Importance: Normal
                          Hello all,
  this mail is about how to localize correctly the standard "Undo (or
Redo) Copy (or Paste, or Edit)" menu item in the MainMenu.nib of a
document-based text editor (say, as in the "Create a text editor in 15
minutes" of the Cocoa documentation) for "exotic" languages with little
or no builtin localization support( I localize my apps for Breton).
  After using undoMenuTitleForUndoActionName (see below) , the result
is only half-satisfying : the menu items are translated correctly only
when they are enabled. When shaded, they return to their default
English form.
  Obviously, I added the localization code at a too superficial layer
of the architecture. Can anyone help me out on this ?
                                                       Ewan
  Relevant parts in my code :
 to localize the "Undo" part, LocalizedUndoManager is a subclass of
NSUndoManager
defined as follows :
  in LocalizedUndoManager.h :
 @interface LocalizedUndoManager : NSUndoManager {}
 @end
  in LocalizedUndoManager.m :
 @implementation LocalizedUndoManager
-(NSString*) redoMenuTitleForUndoActionName:(NSString*) actionName
{
   NSString* redo=NSLocalizedString(@"Redo",@"");
   NSString* newActionName=[[NSBundle mainBundle]
                   localizedStringForKey:actionName
                                   value:actionName
                                   table:@"UndoNames"];
   return [NSString stringWithFormat:@"%@ %@", redo,newActionName];
}
-(NSString*) undoMenuTitleForUndoActionName:(NSString*) actionName
{
   NSString* undo=NSLocalizedString(@"Undo",@"");
   NSString* newActionName=[[NSBundle mainBundle]
                   localizedStringForKey:actionName
                                   value:actionName
                                   table:@"UndoNames"];
   return [NSString stringWithFormat:@"%@ %@", undo,newActionName];
}
@end
 The -init method of class MyDocument contains the two lines
    LocalizedUndoManager* manager=[[LocalizedUndoManager alloc] init];
    [self setUndoManager: manager];
all those ingredients ensure that the "Undo" items will be translated
correctly
when enabled, as long as the developer adds the duly completed
Localized.strings and  UndoNames.Strings file among the resources.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden