Reputation: 2131
In some of my screens in my program the localized strings work and in some it doesn't. (Xcode 4.2)
What I've done:
Added a Localizable.strings in the folder "Resources"
in my .h file, inside the @interface ClassViewController : UIViewController {} I added:
IBOutlet UILable *labelName;
Also in the .h file, I added
property (nonatomic, assign) IBOutlet UILabel *labelName;
In the .m file, I added :
@synthetize labelName;
Still in the .m file, I added inside "-(foid)dealloc" :
[labelName release];
In -(void)viewDidLoad I added :
self.labelName.text = [NSString stringWithFormat:@"KEY"];
Finally, in the xib file (with the Interface manager), I linked the label object with the variable.
So, as I said, this method works in some screen and not in others. Any idea?
Solution:
That what a stupid mistake. the line to enter the text should be:
NSLocalizedString(@"KEY", nil);
Upvotes: 1
Views: 693
Reputation: 31
In XCode-4.2 you can do the following:
It works, hope it will help you.
Upvotes: 1
Reputation: 288
As Vince pointed out, you need to use NSLocalizedString function. So in this case the code in 6 would be:
self.labelName.text = NSLocalizedString(@"The key for this label",@"Some comment");
That should work for you.
Upvotes: 1
Reputation: 40995
What do you imagine this line does?
self.labelName.text = [NSString stringWithFormat:@"KEY"];
Because it's functionally equivalent to writing this:
self.labelName.text = @"KEY";
But I suspect that what you meant to write was this instead:
self.labelName.text = NSLocalizedString(@"KEY", @"description");
Upvotes: 0
Reputation: 1931
Use instead:
self.labelName.text = NSLocalizedString(@"KEY", "");
From the Documentation:
Upvotes: 4