Skip to main content

Localization Module

Ship globally from day one with a production-ready localization system featuring type-safe string keys and automatic pluralization support.
Package location: Packages/Localization/

Overview

The Localization module provides compile-time safe string access, eliminating missing translation errors before they reach users.

Type-Safe Strings

Compile-time safety catches missing translations

Pluralization

Automatic plural rules for every language

2 Languages Included

English and Spanish out of the box

100+ Strings

Pre-localized Auth, Chat, Settings, Payments, Errors

Quick Start

Basic Usage

import Localization

// Type-safe, autocomplete-friendly
Text(L10n.Auth.tagline)           // "Your AI assistant"
Text(L10n.Chat.placeholder)       // "Type a message..."
Text(L10n.Settings.theme)         // "Theme"

// Error messages that make sense
errorLabel.text = L10n.Error.networkOffline
// "You're offline. Please check your internet connection."

Pluralization

The module handles complex plural rules for every language automatically:
// English: "5 messages remaining" / "1 message remaining" / "No messages remaining"
// Russian: Different forms for 1, 2-4, 5-20, etc.
// Arabic: Six different plural forms

Text(L10n.Chat.messagesRemaining(count))

File Structure

Packages/Localization/
├── Package.swift
├── README.md
├── Sources/Localization/
│   ├── L10n.swift              # Type-safe keys
│   ├── Localization.swift       # Module entry
│   └── Resources/
│       ├── en.lproj/           # English
│       │   ├── Localizable.strings
│       │   └── Localizable.stringsdict
│       └── es.lproj/           # Spanish
│           └── Localizable.strings
└── Tests/LocalizationTests/
    └── L10nTests.swift

Adding New Languages

Adding a new language takes just minutes:
1

Copy existing language folder

cp -r en.lproj de.lproj
2

Translate strings

Edit de.lproj/Localizable.strings with German translations
3

Build and test

The app automatically picks up new languages

Adding Custom Strings

1. Add to Localizable.strings

// en.lproj/Localizable.strings
"myFeature.title" = "My Feature";
"myFeature.subtitle" = "This is my new feature";

2. Add Type-Safe Key

// L10n.swift
public enum MyFeature {
    public static var title: String {
        String(localized: "myFeature.title", bundle: bundle)
    }
    
    public static var subtitle: String {
        String(localized: "myFeature.subtitle", bundle: bundle)
    }
}

3. Use in Your Views

Text(L10n.MyFeature.title)
Text(L10n.MyFeature.subtitle)

Pre-Localized Strings

The module includes 100+ pre-localized strings covering common app needs:
  • Sign in / Sign up labels
  • Password fields
  • Error messages
  • Social login buttons
  • Email confirmation
  • Message placeholders
  • Send button
  • Typing indicators
  • Message status (sent, delivered, read)
  • Error states
  • Section headers
  • Theme options
  • Account settings
  • Privacy options
  • About section
  • Subscription labels
  • Price formatting
  • Purchase buttons
  • Restore purchases
  • Error messages
  • Network errors
  • Authentication errors
  • Permission errors
  • Generic errors
  • Retry prompts

Best Practices

Always use L10n

Never hardcode user-facing strings

Test with pseudolocalization

Catch layout issues early

Keep strings short

Some languages expand 30%+

Avoid string concatenation

Use string interpolation instead

Testing

func testLocalizationKeys() {
    // Verify all keys have translations
    XCTAssertFalse(L10n.Auth.tagline.isEmpty)
    XCTAssertFalse(L10n.Chat.placeholder.isEmpty)
    
    // Test pluralization
    XCTAssertEqual(L10n.Chat.messagesRemaining(0), "No messages remaining")
    XCTAssertEqual(L10n.Chat.messagesRemaining(1), "1 message remaining")
    XCTAssertEqual(L10n.Chat.messagesRemaining(5), "5 messages remaining")
}