Is it possible to localize UITabBarItem text in a storyboard automatically?
Another option is to set the titles on the tab bar item to NSLocalizedStrings programmatically.
tabBar.items![0].title = NSLocalizedString("tab1", comment: "")
tabBar.items![1].title = NSLocalizedString("tab2", comment: "")
tabBar.items![2].title = NSLocalizedString("tab3", comment: "")
tabBar.items![3].title = NSLocalizedString("tab4", comment: "")
While you can localize UITabBarItem
s 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.
You can localize UITabBarItem exactly how you localize other storyboard components. In my opinion, the main reason this doesn't work in your case, is because in a Storyboard you have two title: one on the tab bar, another on the view controller...and you are using the wrong ID :-)
Starting from a new project, tabbed application, click on the project (on the left), the Project (not target) on the right, info tab, add a language in the Localizations (I used Italian). Leave all defaults.
Xcode will create this .strings file for the Italian language:
...
/* Class = "IBUIViewController"; title = "First"; ObjectID = "CZ4-MO-1fc"; */
"CZ4-MO-1fc.title" = "First";
/* Class = "IBUIViewController"; title = "Second"; ObjectID = "QUy-BD-bpt"; */
"QUy-BD-bpt.title" = "Second";
/* Class = "IBUITabBarItem"; title = "Second"; ObjectID = "Z7h-1E-pvt"; */
"Z7h-1E-pvt.title" = "Second";
/* Class = "IBUITabBarItem"; title = "First"; ObjectID = "u1e-5L-l1D"; */
"u1e-5L-l1D.title" = "First";
....
As you can see, there are two titles, one on the VC, another on the TabBarItem.
You have to update the titles marked with IBUITabBarItem