iOS Development
Localization
Info.plist
String Localization
Mobile App Development

How to localise a string inside the iOS info.plist file?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Sure, here's a detailed article on how to localize a string inside the iOS Info.plist file, using markdown formatting:


When developing an iOS app, supporting multiple languages can broaden your app's audience significantly. Localizing strings in your app's Info.plist file is crucial since this file contains metadata essential to your app. When these properties are localized, users can experience the app in their preferred language. This guide will walk you through the process of localizing strings in the Info.plist file.

Understanding the Info.plist File

The Info.plist file is a property list file that contains key-value pairs, providing important configuration data about your app. The most common keys used include CFBundleName, CFBundleDisplayName, and NSLocationWhenInUseUsageDescription.

Localizing Strings in Info.plist

Step-by-Step Guide

  1. Create a Localizable.strings File:
    • First, create a Localizable.strings file for each language your app supports. This involves setting up a .lproj folder for each language. For instance, en.lproj for English, fr.lproj for French, etc.
  2. Edit the InfoPlist.strings File:
    • For each localized folder (e.g., en.lproj, fr.lproj), create an InfoPlist.strings file. This is where you'll place localized versions of your Info.plist strings.
  3. Add Localized Key-Value Pairs:
    • In the InfoPlist.strings file, add the keys you wish to localize along with their translations. For instance:
plaintext
1     /* en.lproj/InfoPlist.strings */
2     "CFBundleDisplayName" = "My App";
3     "NSLocationWhenInUseUsageDescription" = "We need access to your location to provide tailored content.";
4
5     /* fr.lproj/InfoPlist.strings */
6     "CFBundleDisplayName" = "Mon Application";
7     "NSLocationWhenInUseUsageDescription" = "Nous avons besoin de votre position pour fournir du contenu adapté.";
  1. Referencing Localized Strings in Info.plist:
    • Instead of hardcoding strings in your Info.plist, ensure it references the InfoPlist.strings. The system will automatically look for translations in the InfoPlist.strings files when the app runs.
  2. Testing Localizations:
    • Deploy the app to a device or simulator, changing the language settings. The strings in your Info.plist should adapt to the language setting of the device.

Technical Considerations

  • Key Names: Remember that key names in InfoPlist.strings must match exactly with those in Info.plist.
  • Character Encoding: Make sure your InfoPlist.strings files are saved using UTF-8 encoding without BOM (Byte Order Mark).
  • Comments: Comments in .strings files should use C-style comments, either line (//) or block (/* ... */).
  • Order: The order of strings in InfoPlist.strings doesn't matter. What's important is that each key has a corresponding value.

Example: Localizing the App Name and Usage Descriptions

Here is an example of localizing the app display name and a usage description for accessing a device feature:

plaintext
1// en.lproj/InfoPlist.strings
2"CFBundleDisplayName" = "Travel Buddy";
3"NSCameraUsageDescription" = "Need access to your camera to take photos.";
4
5// es.lproj/InfoPlist.strings
6"CFBundleDisplayName" = "Compañero de Viaje";
7"NSCameraUsageDescription" = "Necesitamos acceso a su cámara para tomar fotos.";

In this example, English and Spanish localizations have been provided for both the app name and camera usage description.

Summary Table

Below is a summarized table of the key steps and considerations:

Step/ConsiderationDescription
Create Localizable.stringsSet up .lproj folder per language with .strings
Edit InfoPlist.stringsAdd translations for keys like CFBundleDisplayName and NSLocationWhenInUseUsageDescription
Exact Key NamesEnsure keys match between Info.plist and .strings
Use UTF-8 EncodingSave .strings files without BOM
Language TestingVerify changes using different language settings

Additional Details

  • Dynamic Localization: While not directly applicable to InfoPlist.strings, remember that dynamic localization changes (e.g., changing language without restarting) do not apply here. Changes in the system language itself require an app restart to reflect changes.
  • Future-Proofing: Regularly update your localizations in response to user feedback or when adding new features that require metadata in Info.plist.

Localizing your Info.plist strings provides a more inclusive experience for users around the world. With careful setup and testing, you can ensure that your iOS application supports multiple languages effectively, enhancing user satisfaction and market reach.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.