iOS Localization: How to Translate Apple Strings Files with PTC

Learn how to prepare .strings files for translation and translate them with PTC (Private Translation Cloud), making iOS localization fast and easy.

In iOS app development, .strings files store all the user-facing text that appears in your app. Your app loads the right translations from these files, depending on the language the user selects.

This tutorial will guide you through preparing your .strings file for translation and using PTC to localize your app. By understanding your project’s context, PTC delivers context-aware, Better Than Human Translations. Plus, it automatically sends the translated files back to your software repository, streamlining the localization process.

What Does a .strings File Look Like?

A .strings file organizes user-facing text in your app as key-value pairs, mapping the original text to its translations. This file includes all the text users interact with, such as:

Buttons

Text like “Login,” “Submit,” or “Settings”

Notifications

Notifications such as “Your battery is running low”

Error Messages

Alerts or notifications like “An error occurred. Please try again”

Greetings

Like “Welcome to our app!”

Here’s an example of a .strings file for an iOS app:

/* Button title */
"LOGIN_BUTTON" = "Log In";

/* Welcome message */
"WELCOME_MESSAGE" = "Welcome to our app!";

/* Error message for failed login */
"LOGIN_ERROR" = "Incorrect username or password. Please try again.";

In this example:

  • "LOGIN_BUTTON" is the key, and "Log In" is the value that appears on the button.
  • "WELCOME_MESSAGE" displays the "Welcome to our app!" greeting when the user opens the app.
  • "LOGIN_ERROR" shows the "Incorrect username or password. Please try again." error message when a login attempt fails.

Getting Your iOS App Ready for Localization

Before you start translating, it’s important to set up your app’s text correctly. This section explains how to mark text for localization, handle dynamic content, and generate the .strings file.

1. Mark Static Strings for Localization in Xcode

Xcode can generate a .strings file to gather text for translation, but you first need to mark all static, user-facing text in your code for localization.

To do this, identify all hardcoded strings in your app and replace them with the NSLocalizedString function. This function signals to Xcode which strings should be included in the .strings file, making them ready for translation.

For example, here’s how you mark a button label for localization:

label.text = NSLocalizedString("SUBMIT_BUTTON", comment: "Button to submit a form");

In this example:

  • SUBMIT_BUTTON" is the key that will be used in the .strings file
  • The comment provides context and explains what you use the text for

Use clear and descriptive keys in your code. If you use vague keys like “BUTTON1,” Xcode will export them as-is into the .strings file.

Descriptive keys act as identifiers, helping you track where each string appears and making it easier to maintain and update your .strings files.

2. Set Up Dynamic Content in Xcode

For dynamic content like numbers, dates, or usernames, use placeholders to handle these values in localized text.

Just like with static text, use NSLocalizedString in your code to mark dynamic content for translation. Placeholders will be included in the .strings file when you export it from Xcode.

Here’s how to mark dynamic content in your code:

let unreadMessagesCount = 5
let message = String(format: NSLocalizedString("UNREAD_MESSAGES", comment: "Message showing the number of unread messages"), unreadMessagesCount)

In the example above:

  • "UNREAD_MESSAGES" is the key that will go into the .strings file.
  • You’re passing unreadMessagesCount as the dynamic value that will display in the final message.

3. Generate Your .strings File

Once you’ve marked all text in your app with NSLocalizedString, including dynamic content, you can create a .strings file using Xcode’s Export for Localization feature. This file serves as the foundation for translating your app into other languages.

To generate the file:

  1. Open your project in Xcode.
  2. Go to Editor → Export for Localization.
  3. Xcode will generate a .strings file containing all translatable text.

Alternatively, you can create the .strings file manually by identifying all user-facing text in your app and defining a key-value pair for each piece of text.

4. Add Placeholders for Dynamic Content

After generating your .strings file, you’ll need to ensure dynamic content displays correctly by adding placeholders.

For entries with dynamic values (like numbers or dates), insert the appropriate format specifier, such as %d for integers or %@ for strings, where the value should appear.

Here’s how to do it:

  1. Open the .strings file and locate keys with dynamic content.
"UNREAD_MESSAGES" = "Message showing the number of unread messages";
  1. Add the placeholder where the dynamic value belongs.
"UNREAD_MESSAGES" = "You have %d unread messages";
  1. Save the .strings file.

5. Handle Pluralization with .stringsdict Files

To manage pluralization (e.g., “1 message” vs. “2 messages”), create a .stringsdict file. These files define pluralization rules for different languages, something a .strings file alone can’t handle.

For more on preparing and translating .stringsdict files, check out our tutorial on .stringsdict files.

Translating Your .strings File with PTC

Once your .strings file is ready, PTC makes the translation process fast and easy. By integrating with your repository, PTC handles everything from detecting files to delivering translations as merge requests, keeping your app localized at all times.

Step 1: Connect to Your Repository

Start by connecting PTC to your code repository. PTC automatically detects your .strings files (and .stringsdict files, if included). During this step, you’ll set up the target languages for translation and complete the project setup.

Step 2: AI-Powered Better Than Human Translations

PTC delivers delivers high-quality translations by understanding your app’s context. Whether your app is in gaming, education, or finance, PTC uses this context to create Better Than Human Translations.

Step 3: Translations Delivered as Merge Requests

After translating your files, PTC sends them to your repository as a merge request ans continues to monitor your repository for changes. When you update your source files, it detects the changes, updates the translations, and sends a new merge request.

Get Fast, High-Quality, and Instant Translations with PTC

This guide covered how to mark text for localization, prepare your .strings files, and use PTC to translate your app efficiently.

With a PTC subscription, you get:

  • Integration with your software repository for a straightforward process
  • Better Than Human Translations tailored to your app’s context
  • Automatic updates whenever your .strings files change

Try PTC for free

Start your free 30-day trial and discover how easy it is to localize your iOS or macOS app with PTC.

Scroll to Top