Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 2, 2008, 08:15 PM   #1
Darkroom
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
Localize NSMenu Title

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.
Attached Files
File Type: zip LocalizeNSMenu.zip (47.5 KB, 20 views)
Darkroom is offline   0 Reply With Quote
Old Nov 10, 2008, 03:14 PM   #2
kanenas
macrumors newbie
 
Join Date: Jun 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:
    1. select the NIB/XIB in Resources
    2. get info (cmd-I or File->Get Info)
    3. "General" tab
    4. click "Add Localization" button at bottom of window
    5. 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.
kanenas is offline   0 Reply With Quote
Old Nov 10, 2008, 06:27 PM   #3
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
hi... your suggested procedure is exactly what i've been trying to avoid

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...
Darkroom is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Why am I getting such a low Local Network file transfer speed? alexreich Mac Basics and Help 1 Apr 13, 2012 01:48 AM
iTunes not sending Titles to Nicecast siys Mac Applications and Mac App Store 0 Jul 22, 2011 04:06 PM
Help with localization (using nib files) Nekbeth iPhone/iPad Programming 2 Jun 23, 2011 08:47 AM
NSMenu title cut off S0ULphIRE Mac Programming 4 Apr 29, 2010 02:55 AM


All times are GMT -5. The time now is 11:41 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC