How to localize an iOS storyboard

Objective CIosNslocalizedstringUistoryboard

Objective C Problem Overview


I've an iPhone storyboard with some views. For instance, a navigation item title is named News, which should be translated for other languages.

When I add a new localization to my storyboard, it created a duplicate of my current storyboard for the new language. Here I can change the title for the navigation item, but for me it does not seem very useful. What if my storyboard contains 100 views and I need to support 10 languages? If I need to change something in my original storyboard, I have to make the same changes for all languages. That seems very odd. In which situations can this be useful?

What can I do instead? Should I have only the english storyboard and manually translate each element in the ViewController using NSLocalizedString?

Objective C Solutions


Solution 1 - Objective C

In iOS 6 there is a Project setting under the Info tab that says "Use Base Internationalization". If you check the box, it will pull all of the strings out of the Storyboard and into internationalized .strings files.

This way you don't have to have multiple copies of the Storyboard.

enter image description here

Solution 2 - Objective C

As of iOS 6 you can decide to use Base Internationalization: All storyboard and xib/nib files exist only once in a folder named Base.lproj. The localization of the GUI elements is placed in related .strings files in each localization directory.

For example "MainStoryboard.storyboard" will be placed in Base.lproj. An associated file called "MainStoryboard.strings" is placed in en.lproj and whatever localization you apply.

This is really very handsome, especially in combination with layout constraints!

Solution 3 - Objective C

You can do the localization by changing the titles of the UI elements in code:

self.title = NSLocalizedString("News", nil);

If you want to localize your app in Dutch for example, you would have this in Dutch.lproj/Localizable.strings:

"News" = "Nieuws";

You can then do this for every UI element and language.

Solution 4 - Objective C

You might find this video tutorial here useful:

http://www.youtube.com/watch?v=cF1Rf02QvZQ

The approach is to have a separate storyboard for each language to localize, then let a script take care of propagating the changes you make in the original storyboard for all other languages.

Solution 5 - Objective C

For apps with a deployment target of iOS 5 and storyboards I use something like this to localize my tabs where my first ViewController on a storyboard is a UITabBarController:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
	// ...

	if ([self.window.rootViewController isKindOfClass:UITabBarController.class]) {
		UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController;
		
		// Localize tab items
		NSArray *tabBarItems = tabBarController.tabBar.items;
		
		[tabBarItems enumerateObjectsWithOptions:NSEnumerationConcurrent 
									  usingBlock:^(UITabBarItem *item, NSUInteger tabIndex, BOOL *stop) {
			NSString *keyName = [NSString stringWithFormat:@"tabBarItem%i", tabIndex];
			item.title = NSLocalizedString(keyName, @"TabBarItems");
		}];
	} else {
		// The root view controller is not the UITTabBarController
	}

	// ...
}

and have something like this in my Localizable.strings files:

// MARK: TabBar
"tabBarItem0" = "My First Tab Label";
"tabBarItem1" = "My Second Tab Label";
"tabBarItem2" = "My Third Tab Label";

Solution 6 - Objective C

You might find Polyglot Localization useful as well. In stead of calling NSLocalizedString() in code, you can directly specify the key it in your Storyboard. You can avoid unnecessary outlets and reduce boilerplate code.

https://github.com/negusoft/Polyglot

Solution 7 - Objective C

I suggest you learn the commandline ibtool it helps asist you in localizing all of your storyboards :) Here is a tutorial here http://www.albertmata.net/articles/introduction-to-internationalization-using-storyboards-on-ios-5.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondhrmView Question on Stackoverflow
Solution 1 - Objective CCollinView Answer on Stackoverflow
Solution 2 - Objective CfreytagView Answer on Stackoverflow
Solution 3 - Objective Cuser142019View Answer on Stackoverflow
Solution 4 - Objective CreabrnView Answer on Stackoverflow
Solution 5 - Objective CJens KohlView Answer on Stackoverflow
Solution 6 - Objective CblurkidiView Answer on Stackoverflow
Solution 7 - Objective CJames CampbellView Answer on Stackoverflow