Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to localize UITabBarItem text in a storyboard automatically?

I'm new to native iOS development, and have been playing with localizing storyboards.

I've been localizing the text for UILabel and UIButton objects in my storyboard by updating the Main.strings files for the storyboard:

// UIButton:
"cEx-Yi-RY8.normalTitle" = "Done";

// UILabel:
"1l2-H9-hRc.text" = "Safety information!";

How do I do the same for a UITabBarItem? I have tried:

//UITabBarItem:
"oSH-y1-hFoB.title" = "Scan";

But it doesn't work :(

I don't get why... I can see it is possible to update the text manually in the UITabBarController:

- (void)viewDidLoad
{
    //...
    item.title = NSLocalizedString(@"scan", nil);
}

But then I have to put those translations in a separate Localizable.strings file, which seems lame.

On the other hand, at least the translations in Localizable.strings are somewhat readable, i.e. "scan" = "Scan"; rather than "oSH-y1-hFoB.title" = "Scan"; ...

Still... I'm not following why some stuff works in Interface Builder but other stuff doesn't and you have to do it manually.

I hate having to add all this boilerplate code to do repetitive stuff like localizing text in the UI, when the framework should just be able to do it for me. (If it can do it for a UIButton, why not a UITabBarItem...)

Or am I just overlooking something?

like image 637
asgeo1 Avatar asked Jul 28 '14 05:07

asgeo1


1 Answers

While you can localize UITabBarItems just like any other StoryBoard component, be aware that if you set a title for the associated view controller, it will overwrite the title of the UITabBarItem. That will prevent your localizations from appearing.

like image 62
Tad Avatar answered Sep 17 '22 15:09

Tad