0Pricing
Swift Academy · Lesson

String Catalogs and Localized Strings

Localize text with the modern String Catalog.

String Catalogs and Localized Strings is a free Swift Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Localize at All

Localization (l10n) means presenting your app's text in the user's language; internationalization (i18n) means structuring code so that localization is possible. The first step is to stop hardcoding user-facing strings and instead pull them from a resource catalog.

// Hardcoded — bad for localization
// let title = "Welcome"

// Localized — looked up by key
let title = String(localized: "Welcome")

String Catalogs

Modern Xcode projects use a String Catalog (.xcstrings file). It is a single JSON-backed file that lists every localizable key, its translations per language, and metadata like comments and pluralization. Xcode can auto-extract keys from your code.

// Localizable.xcstrings holds entries like:
// key: "Welcome"
//   en: "Welcome"
//   tr: "Hos geldiniz"
//   ja: "Yokoso"

String(localized:)

In code, String(localized:) resolves a key at runtime to the translation for the current locale. The literal you pass doubles as the key and as the development-language fallback.

let greeting = String(localized: "Welcome back")
let cancel = String(localized: "Cancel")
print(greeting)

Adding Comments for Translators

A bare word like Run can mean execute or jog. The comment: parameter gives translators context so they pick the right wording. Comments flow into the String Catalog automatically.

let runLabel = String(
    localized: "Run",
    comment: "Button that executes the user's code")

Interpolating Values

You can embed runtime values in a localized string. Swift turns each interpolation into a format placeholder so translators can reorder them. Different languages put the subject and number in different positions.

let name = "Mira"
let count = 3
let msg = String(localized: "\(name) has \(count) new messages")
print(msg)

LocalizedStringKey in SwiftUI

In SwiftUI you rarely call String(localized:) directly. Most text-accepting views take a LocalizedStringKey, so a plain string literal is localized automatically.

// In SwiftUI — the literal is a LocalizedStringKey
// Text("Welcome back")        // auto-localized
// Button("Save") { save() }   // auto-localized
let key: LocalizedStringKey = "Welcome back"
_ = key

Avoiding Accidental Localization

Because SwiftUI treats literals as keys, a dynamic String variable is not localized. If you build text by concatenation, the catalog never sees the real key. Pass a single literal whenever you want localization, and use verbatim: when you explicitly do not.

let userInput = "hello"
// Text(userInput)            // NOT a localization key
// Text(verbatim: userInput)  // explicitly raw, never localized
let verbatimKey = userInput
_ = verbatimKey

Specifying a Table

Large apps split strings across multiple catalogs (tables). You can target a specific table and bundle, which is essential when shipping strings inside a framework or Swift package.

let onboardingTitle = String(
    localized: "Get Started",
    table: "Onboarding",
    bundle: .main)

LocalizedStringResource

LocalizedStringResource represents a localizable string as a value you can store and resolve later, even across processes (useful for App Intents and widgets). It defers the actual lookup until display time.

let resource = LocalizedStringResource("Order shipped")
// Resolve later, possibly in another locale context
let resolved = String(localized: resource)
print(resolved)

The Default Localization

The project's development language provides the fallback when a translation is missing. The string literal you write in code is treated as the source-language value, so your code stays readable and you never ship a raw key like welcome_screen_title to users.

// If only 'en' is translated and device is set to 'fr',
// the development-language value is shown as fallback.
let fallback = String(localized: "Settings")
print(fallback)

A Realistic Lookup

Putting it together: a function that returns a fully localized, context-annotated, interpolated message ready for any UI.

func welcomeMessage(for user: String) -> String {
    return String(
        localized: "Welcome, \(user)!",
        comment: "Greeting shown after sign-in")
}
print(welcomeMessage(for: "Ada"))

Quick Check

Recall how SwiftUI decides whether to localize text.

Recap

You set up the foundation of localized text:

  • Store translations in a String Catalog (.xcstrings).
  • Look up strings with String(localized:), adding comment: for translators.
  • In SwiftUI, literals become LocalizedStringKey and localize automatically; variables do not.
  • Use table:/bundle: for frameworks and LocalizedStringResource for deferred resolution.

Frequently asked questions

Is the “String Catalogs and Localized Strings” lesson free?

Yes — the full text of “String Catalogs and Localized Strings” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

What will I learn in “String Catalogs and Localized Strings”?

Localize text with the modern String Catalog. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “String Catalogs and Localized Strings” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. String Catalogs and Localized Strings
  2. Pluralization and Stringsdict
  3. Locale-Aware Formatting
  4. Right-to-Left and Layout Direction
← Back to Swift Academy