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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With