Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl and localization

I have a .xib file, with accompanying .strings files for different languages. The .xib file contains a label, and a UISegmentedControl.

When asking IB to localize the .xib file, I get the following .strings file:

"6.segmentTitles[0]" = "title1";
// ...More strings related to the segmented control...
"11.text" = "bla";

The 'bla' string belongs to the label.

Changing the 'bla` string is reflected in runtime, while changing the 'title1' string does not. Anyone knows why?

like image 706
user1071136 Avatar asked Oct 07 '22 08:10

user1071136


1 Answers

This question is not new, but as it is still without any answers I will add my solution as it may help others.

Generally, as it's mentioned above, it is an open bug that UISegmentedControl segment titles do not pick up localization strings.

- (void)viewDidLoad
{
    ...

    // Locale will be picked automatically by NSBundle.
    NSString *resourcePath  =[[NSBundle mainBundle] pathForResource:@"MainStoryboard" ofType:@"strings"];
    NSDictionary *resourceDict = [NSDictionary dictionaryWithContentsOfFile:resourcePath];
    [self.segmentedControl setTitle:[resourceDict objectForKey:@"COo-BO-Ryl.segmentTitles[0]"] forSegmentAtIndex:0];
    [self.segmentedControl setTitle:[resourceDict objectForKey:@"COo-BO-Ryl.segmentTitles[1]"] forSegmentAtIndex:1];

}

Where COo-BO-Ryl is the Object ID of segmentedControl.

Not very pretty, but does the job.

like image 62
Maciej Jastrzebski Avatar answered Oct 10 '22 04:10

Maciej Jastrzebski