Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
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

Code:
#import <Cocoa/Cocoa.h>

@interface AppController : NSObject
	{
	//Main Menu Outlets
	IBOutlet id MenuItem1;
	IBOutlet id MenuItem2;
	}

@end





#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];
	}
	
@end

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.
 

Attachments

  • LocalizeNSMenu.zip
    47.5 KB · Views: 93

kanenas

macrumors newbie
Jun 20, 2008
24
0
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.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
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:

Code:
[[[[NSApp mainMenu] itemAtIndex:1] submenu] setTitle:NSLocalizedString(@"File", nil)];

the above works perfectly...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.