How to localize your iOS storyboard

I have an iPhone storyboard with some looks. For example, the title of a navigation item is called " News ," and should be translated into other languages.

When I add a new localization to my storyboard, it creates a copy of my current storyboard for the new language. Here I can change the name for the navigation element, 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. It seems very strange. In what situations can this be useful?

What can I do instead? Should I have only an English storyboard and manually translate each item in the ViewController using NSLocalizedString ?

+54
ios objective-c uistoryboard nslocalizedstring
Nov 29 '11 at 2:59 p.m.
source share
7 answers

You can perform localization by changing the headers of the interface elements in the code:

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

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

 "News" = "Nieuws"; 

You can then do this for each element and user interface language.

+10
Dec 6 '11 at 16:27
source share

In iOS 6, the “Information” tab has the option “Use basic internationalization”. If you check the box, it will pull all the lines from the storyboard and into the internationalized .strings files.

This way you do not need to have multiple copies of the storyboard.

enter image description here

+107
04 Oct '12 at 16:18
source share

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

For example, "MainStoryboard.storyboard" will be placed in Base.lproj. A linked file called "MainStoryboard.strings" is placed in en.lproj and any localization you use.

It is really very beautiful, especially in combination with layout limitations!

+39
Jul 21 2018-12-21T00:
source share

You may find this video here:

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

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

+6
Mar 13 2018-12-12T00:
source share

For applications with the goal of deploying iOS 5 and storyboards, I use something like this to localize my tabs, where my first ViewController on the storyboard is 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"; 
+3
Mar 27 '13 at 9:20
source share

You can also find Polyglot Localization. Instead of calling NSLocalizedString () in code, you can directly specify the key in your storyboard. You can avoid unnecessary exits and reduce the template code.

https://github.com/negusoft/Polyglot

+2
Oct 12 '15 at 19:36
source share

I suggest you study the ibtool command line, which helps you localize all your storyboards :) Here is a tutorial here http://www.albertmata.net/articles/introduction-to-internationalization-using-storyboards-on-ios-5.html

+1
Aug 02 2018-12-12T00:
source share



All Articles