Use Your Loaf

[[brain engage] write]

Localize iPhone Application Name

Some time ago I wrote a post about adding a settings bundle to an iPhone App that received a number of questions about how to change the application name that is shown under the icon on the iPhone home screen and in the settings application. So I thought I would finally get around to showing how you can use the localization capabilities of iOS to change the application name. I will cover localizing the strings inside a settings bundle in a follow up post.

CFBundleDisplayName

The steps to localise the application name are actually very simple but like many things with iOS it can take some hunting around to fully understand what you need to do. The secret is to localise the value of the CFBundleDisplayName key contained in an applications Information Property List (Info.plist) file. The Apple documentation for this key is as follows:

CFBundleDisplayName (String – iOS, Mac OS X) specifies the display name of the bundle. If you support localized names for your bundle, include this key in both your information property list file and in the InfoPlist.strings files of your language subdirectories. If you localize this key, you should also include a localized version of the CFBundleName key.

If you do not intend to localize your bundle, do not include this key in your Info.plist file. Inclusion of this key does not affect the display of the bundle name but does incur a performance penalty to search for localized versions of this key.

Before displaying a localized name for your bundle, the Finder compares the value of this key against the actual name of your bundle in the file system. If the two names match, the Finder proceeds to display the localized name from the appropriateInfoPlist.strings file of your bundle. If the names do not match, the Finder displays the file-system name.

By default when you create an iOS application Xcode populates a default Info.plist file with values for both the CFBundleDisplayName (“Bundle display name”) and the CFBundleName (“Bundle name”) keys. By default these keys are both set to ${PRODUCT_NAME} which is set to the name used when creating the project. You do NOT need to change these keys in the Info.plist file.

InfoPlist.strings

To localize the value of an Info.plist key we need to add an InfoPlist.strings file to the project. We can do that in the usual way by right-clicking on the Resources group and selecting “Add –> New File…” and choosing the Strings file template from the Mac OS X Resource section (for some reason the Strings file template is not included in the iOS Resource section). Give the new file the name InfoPlist.strings and ensure it is added to the current target:

Before we localise the file we can add the default values for the English locale. We will add values for both the CFBundleDisplayName and CFBundleName keys though for iOS the important one is the bundle display name:

"CFBundleDisplayName" = "Hello";
"CFBundleName" = "Hello";

Our example app is named Hello in the English locale. To localise the file, right-click on it and select “Get Info” to open the file info window and click the “Make File Localizable” button at the bottom of the dialog:

On the General tab of the Localized dialog there is a button to “Add Localization” that we can use to add each of the required locales. For the purposes of this example I will add “en” (English), “it” (Italian) and “es” (Spanish) locales. (For a discussion on the Xcode issues around the use of “en” and “English” locales see this post on Xcode localization frustrations.)

Once all the locales have been added the dialog should look like this:

The InfoPlist.strings file in the Xcode Groups & Files window should now expand into a list of files named for each locale.

We can now modify each of these language specific versions to set the application name for each locale. So the version for the “it” locale now becomes:

"CFBundleDisplayName" = "Ciao";
"CFBundleName" = "Ciao";

Likewise the version for the “es” locale is modified as follows:

"CFBundleDisplayName" = "Hola";
"CFBundleName" = "Hola";

Build and Run

To test it out we just need to build and run the app in the simulator and change the language settings (Settings –> General –> International –> Language). Setting the language to “Italiano” changes the name to “Ciao” both under the icon, the settings application and when searching for the app:

If we change the language to “Espanol” the name changes to “Hola”:

Setting the language back to English resets the application name to “Hello”.

Wrapping Up

You can find the example app that demonstrates how to customise the application name here. I will cover how to localize the strings inside a settings bundle in a follow up post.

Comments