iOS Localization

iOS Localization

Localization is the process of translating and adapting your app's content to different languages, regions, and cultures.

If you want your app to succeed globally, hardcoding English text into your views is a massive mistake.

Apple provides incredibly powerful, built-in tools to handle multiple languages effortlessly.


String Catalogs (Xcode 15+)

In the past, developers used .strings files to manage translations manually.

Starting in Xcode 15, Apple introduced String Catalogs (.xcstrings), a visual, interactive way to manage localizations.

When you build your app, Xcode automatically scans your code for localized strings and populates this catalog for you!


Using Localized Strings

In SwiftUI, almost all text elements natively look for localized keys by default.

When you write Text("Hello"), SwiftUI actually searches your String Catalog for the key "Hello" in the user's active language.

Localized Strings:

import SwiftUI

struct GreetingView: View { var body: some View { VStack { // This automatically localizes! Text("Welcome to the app!") // If you need the string outside a View, use String(localized:) Button(String(localized: "Continue")) { print("Action triggered") } } } }

If the user's phone is set to Spanish, and you've provided a Spanish translation for "Welcome to the app!", iOS seamlessly swaps it out.


Formatting Numbers and Dates

Localization isn't just about translating words; it's about cultural formatting.

Different countries format dates, numbers, and currencies entirely differently (e.g., 1,000.50 vs 1.000,50).

You should never format these manually. Always use Swift's built-in formatters.

Automatic Formatting:

struct FinanceView: View {
    let accountBalance = 1500.75
    let today = Date()
    var body: some View {
        VStack {
            // Automatically uses the correct currency symbol and decimal format
            Text(accountBalance, format: .currency(code: "USD"))
            // Automatically orders the day, month, and year correctly based on region
            Text(today, format: .dateTime.day().month().year())
        }
    }
}

Pluralization

Languages have complex rules for pluralization. English just adds an "s", but languages like Russian or Arabic have multiple plural forms.

String Catalogs handle this beautifully by allowing you to define different text for zero, one, two, few, many, and other item counts directly in the Xcode UI!


Exercise

Which modern Xcode feature automatically tracks and manages your app's translations in a visual editor?