Like unit testing, localization is one of those things most developers know they should do, but end up skipping for one reason or another.

In Xcode 4, using localized strings is a piece of cake. To start, create a new strings file to store your default localization. Select “New File…” (Command-N or Control-click in the Project Navigator) and choose “Strings File” under iOS > Resource.

Once you’ve created the strings file, you need to localize it. Open up the File Inspector (Command-Option-1 or View > Utilities > File Inspector) and click on the plus sign under Localization. Select the language to localize and you’re good to go.

Here’s an example of a strings file:

  App Name

  Created by Miscellanea on 10/20/11.
  Copyright 2011 __MyCompanyName__. All rights reserved.

"MainViewTitle" = "App Name";

"InfoViewTitle" = "About";
"InfoViewDoneButtonTitle" = "Done";

"AuthorInfo" = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";

Strings can fit on a single line or wrap across multiple lines.

Once you have a few localized strings, it’s a piece of the aforementioned cake to reference them in your Xcode project. For example, here’s how to set the title in the root view controller using a localized string:

– (void)viewDidLoad
    [super viewDidLoad];

    self.title = NSLocalizedString(@"MainViewTitle", @"");

Things get a bit more complicated when you have multiple bundles and tables, but the above should suffice for most projects.