How to localize an iOS storyboard

53,363

Solution 1

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

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

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 4

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 5

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

Share:
53,363
dhrm
Author by

dhrm

Updated on January 22, 2020

Comments

  • dhrm
    dhrm over 4 years

    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?