1
votes

I have an iPad app (XCode 4.6, iOS 6.2, Storyboards and ARC). I am trying to localize a UISegmentControl. I already have the translations in MainStoryboard.strings file, and have this code in the controller's viewDidLoad:

    //  set titles of UISegmentedControls
NSString *resourcePath  =[[NSBundle mainBundle] pathForResource:@"MainStoryboard" ofType:@"strings"];
NSDictionary *resourceDict = [NSDictionary dictionaryWithContentsOfFile:resourcePath];

[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:@"jcy-vN-Nq9.segmentTitles[0]"] forSegmentAtIndex:0];
[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:@"jcy-vN-Nq9.segmentTitles[1]"] forSegmentAtIndex:1];
[self.oDeleteOldAppts setTitle:[resourceDict objectForKey:@"jcy-vN-Nq9.segmentTitles[2]"] forSegmentAtIndex:2];

The problem is that both resourcePath and resourceDict are nil. How do I get them for the current language, be it en or some other language?

2

2 Answers

0
votes

Don't do any of that. You localize the storyboard by editing the .strings file that goes with it for the appropriate language. When iOS displays the view, it'll automatically grab the proper localization and display it.

EDIT: If you want to pull something from the strings file, do something like this:

[[NSBundle mainBundle] localizedStringForKey:@"someKeyHere" value:nil table:@"MainStoryboard"];
0
votes

Since UISegmentedControls can't have their title localized, I replaced them with RadioButtons I got from GitHub; localized the labels, moved the radio buttons next to them and it works like a champ.

UPDATE One problem - there doesn't appear to be any way to persist the settings from run to run, therefore, this is not going to work. I am now creating my own custom button and emulating a UISegmentedControl. Works with no problems...