Reputation: 2942
I am adding localization support in my project where I have added Localizable.strings file, and adding key value pair as below:
"not_found" = "device not found";
I am then adding a label to my viewcontroller file as below:
self.notificationTextLabel.text = [NSString stringWithFormat:NSLocalizedString(@"not_found", nil)];
When I run the app label shows not_found instead of "device not found". I have followed tutorials and still not able to figure out why the key is printed. What I could be doing wrong?
Here's what my Project navigator shows:
each contains single line as shown above. French version has translated string.
Also the storyboard also has localizations enabled and has .strings files:
Update: There is a similar question with not very helpful answers. Localization issue Xcode
Upvotes: 0
Views: 885
Reputation: 2942
Found the solution! It was something unexpected. I had created a localizable.strings file earlier and It was conflicting with the newly created file. I deleted all new files and kept only Original file. Works like a charm now!
Upvotes: 0
Reputation: 52632
This happens if the localization isn't found.
One problem is that if the compiler finds any problem in a localizable.strings file, that entry and all following entries are silently ignored. So look what's in the file, and see if other entries earlier in the file work.
BTW. [NSString stringWithFormat... ] expects a format string. What you are doing will get you into all kinds of trouble if you ever use a translation that contains a percent character. Just write
self.notificationTextLabel.text = NSLocalizedString(@"not_found", nil);
Upvotes: 1