5

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?

2
  • 1
    There's this OpenRadar but it hasn't been triaged yet. Oct 30, 2012 at 16:43
  • 9 years later this bug is still there. Mar 28, 2021 at 11:53

1 Answer 1

4

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.

1
  • In his code OP used the xib version, and in my I used the storyboard version, but otherwise the solution should work. Apr 18, 2013 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.