Localize NSMenu Title

Discussion in 'Mac Programming' started by Darkroom, Nov 2, 2008.

  1. Darkroom Guest


    Dec 15, 2006
    Montréal, Canada
    is this not possible? i have all my NSMenuItems hooked up and localized fine, but the NSMenu title is not being localized

    #import <Cocoa/Cocoa.h>
    @interface AppController : NSObject
    	//Main Menu Outlets
    	IBOutlet id MenuItem1;
    	IBOutlet id MenuItem2;
    #import "AppController.h"
    static NSString * CONSTMenuItem1;
    static NSString * CONSTMenuItem2;
    @implementation AppController
    - (void)awakeFromNib
    	CONSTMenuItem1 = NSLocalizedString (@"ENGLISH MENU", nil);
    	[MenuItem1 setTitle:CONSTMenuItem1];
    	CONSTMenuItem2 = NSLocalizedString (@"English Item...", nil);
    	[MenuItem2 setTitle:CONSTMenuItem2];
    i can't seem to hook up the NSMenu in IB, only it's NSMenuItem, so maybe this is why it's not working? i've attached the proj.

    any help would be great.

    Attached Files:

  2. kanenas macrumors newbie

    Jun 20, 2008
    Internationalisation via Interface Builder

    If you don't need to localize programmatically, here's the procedure:
    1. in XCode, add a localisation to the NIB/XIB:
      • select the NIB/XIB in Resources
      • get info (cmd-I or File->Get Info)
      • "General" tab
      • click "Add Localization" button at bottom of window
      • Name the locale. Apple recommends using short names (Alpha-2 of ISO 3166).
    2. Expand the NIB/XIB in XCode
    3. Open the localized interface in IB by double-clicking on it
    4. Edit away
    This is better than the programmatic approach as you can change not only text but layout, which is important when the label text has different widths in different locales. It's also easier and more efficient (you don't need to do all that stuff in awakeFromNib).

    As for why your approach didn't work, I think you're spot on that it's because you don't have a pointer to the NSMenu. Any reason you didn't add a menu outlet to your controller and target the NSMenu in IB? Of course it's now unnecessary, given the above localization procedure.
  3. Darkroom thread starter Guest


    Dec 15, 2006
    Montréal, Canada
    hi... your suggested procedure is exactly what i've been trying to avoid :p

    i'm aware that is how to localize normally, but for me i just find it much easier to have a localization class with all the NSString constants so i can keep track easier...

    i received the answer from another board a while back:

    [[[[NSApp mainMenu] itemAtIndex:1] submenu] setTitle:NSLocalizedString(@"File", nil)];
    the above works perfectly...

Share This Page