Search code examples
ios6localizationxcode4.6

How to get iOS resource dictionary from resource path for current language?


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?


Solution

  • 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...