$npx -y skills add rshankras/claude-code-apple-skills --skill localization-setupGenerate internationalization (i18n) infrastructure for multi-language support in iOS/macOS apps. Use when localizing for multiple languages, adopting String Catalogs (xcstrings), or supporting RTL languages.
| 1 | # Localization Setup Generator |
| 2 | |
| 3 | Generate internationalization (i18n) infrastructure for multi-language support in iOS/macOS apps. |
| 4 | |
| 5 | ## When This Skill Activates |
| 6 | |
| 7 | - User wants to localize their app for multiple languages |
| 8 | - User mentions i18n, internationalization, or localization |
| 9 | - User asks about String Catalogs or .strings files |
| 10 | - User wants to support RTL (right-to-left) languages |
| 11 | |
| 12 | ## Pre-Generation Checks |
| 13 | |
| 14 | Before generating, verify: |
| 15 | |
| 16 | 1. **Existing Localization** |
| 17 | ```bash |
| 18 | # Check for existing localization files |
| 19 | find . -name "*.xcstrings" -o -name "Localizable.strings" 2>/dev/null | head -5 |
| 20 | find . -name "*.lproj" -type d 2>/dev/null | head -5 |
| 21 | ``` |
| 22 | |
| 23 | 2. **Deployment Target** |
| 24 | ```bash |
| 25 | # String Catalogs require iOS 16+ / macOS 13+ |
| 26 | grep -r "IPHONEOS_DEPLOYMENT_TARGET\|MACOSX_DEPLOYMENT_TARGET" *.xcodeproj 2>/dev/null |
| 27 | ``` |
| 28 | |
| 29 | 3. **Project Structure** |
| 30 | ```bash |
| 31 | # Find project for adding localization |
| 32 | find . -name "*.xcodeproj" | head -1 |
| 33 | ``` |
| 34 | |
| 35 | ## Configuration Questions |
| 36 | |
| 37 | ### 1. Localization Approach |
| 38 | - **String Catalogs** (Recommended, iOS 16+) - Modern, visual editor in Xcode |
| 39 | - **Legacy .strings** - Traditional approach, all iOS versions |
| 40 | |
| 41 | ### 2. Initial Languages |
| 42 | - English (en) - default |
| 43 | - Which additional languages? (e.g., es, de, fr, ja, zh-Hans) |
| 44 | |
| 45 | ### 3. Features |
| 46 | - **Pluralization** - Handle "1 item" vs "2 items" |
| 47 | - **Device-specific** - Different strings for iPhone/iPad/Mac |
| 48 | - **SwiftUI Preview** - Preview in different locales |
| 49 | |
| 50 | ## Generated Files |
| 51 | |
| 52 | ### String Catalogs (Recommended) |
| 53 | ``` |
| 54 | Resources/ |
| 55 | └── Localizable.xcstrings # String catalog with all translations |
| 56 | ``` |
| 57 | |
| 58 | ### Supporting Code |
| 59 | ``` |
| 60 | Sources/Localization/ |
| 61 | ├── LocalizedStrings.swift # Type-safe string access |
| 62 | ├── LocalizationManager.swift # Runtime language switching |
| 63 | └── LocalizedPreview.swift # SwiftUI preview helpers |
| 64 | ``` |
| 65 | |
| 66 | ## Key Features |
| 67 | |
| 68 | ### Type-Safe String Access |
| 69 | |
| 70 | ```swift |
| 71 | // Generated enum for type-safe access |
| 72 | enum L10n { |
| 73 | static let appName = String(localized: "app_name") |
| 74 | static let welcomeMessage = String(localized: "welcome_message") |
| 75 | |
| 76 | enum Settings { |
| 77 | static let title = String(localized: "settings_title") |
| 78 | static let language = String(localized: "settings_language") |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Usage |
| 83 | Text(L10n.appName) |
| 84 | Text(L10n.Settings.title) |
| 85 | ``` |
| 86 | |
| 87 | ### Pluralization |
| 88 | |
| 89 | ```swift |
| 90 | // In String Catalog, define plural rules |
| 91 | // key: "items_count" |
| 92 | // variations: |
| 93 | // - zero: "No items" |
| 94 | // - one: "1 item" |
| 95 | // - other: "%lld items" |
| 96 | |
| 97 | Text(String(localized: "items_count \(count)", |
| 98 | defaultValue: "\(count) items")) |
| 99 | ``` |
| 100 | |
| 101 | ### String Interpolation |
| 102 | |
| 103 | ```swift |
| 104 | // In String Catalog: |
| 105 | // key: "greeting" |
| 106 | // value: "Hello, %@!" |
| 107 | |
| 108 | let name = "Alice" |
| 109 | Text(String(localized: "greeting \(name)")) |
| 110 | ``` |
| 111 | |
| 112 | ### Runtime Language Switching |
| 113 | |
| 114 | ```swift |
| 115 | // Preview in different locale |
| 116 | struct ContentView_Previews: PreviewProvider { |
| 117 | static var previews: some View { |
| 118 | ContentView() |
| 119 | .environment(\.locale, Locale(identifier: "es")) |
| 120 | } |
| 121 | } |
| 122 | ``` |
| 123 | |
| 124 | ## Integration Steps |
| 125 | |
| 126 | ### 1. Add String Catalog |
| 127 | |
| 128 | 1. In Xcode: File > New > File |
| 129 | 2. Choose "String Catalog" |
| 130 | 3. Name it "Localizable.xcstrings" |
| 131 | 4. Add to your app target |
| 132 | |
| 133 | ### 2. Add Supported Languages |
| 134 | |
| 135 | 1. Select project in navigator |
| 136 | 2. Info tab > Localizations |
| 137 | 3. Click + to add languages |
| 138 | |
| 139 | ### 3. Migrate Existing Strings |
| 140 | |
| 141 | If migrating from .strings files: |
| 142 | 1. Right-click .strings file |
| 143 | 2. "Migrate to String Catalog..." |
| 144 | |
| 145 | ### 4. Use in SwiftUI |
| 146 | |
| 147 | ```swift |
| 148 | // Automatic localization |
| 149 | Text("Hello, World!") // Uses String Catalog automatically |
| 150 | |
| 151 | // Explicit localized string |
| 152 | Text(String(localized: "custom_key")) |
| 153 | |
| 154 | // With type-safe enum (generated) |
| 155 | Text(L10n.welcomeMessage) |
| 156 | ``` |
| 157 | |
| 158 | ### 5. Use in UIKit |
| 159 | |
| 160 | ```swift |
| 161 | label.text = String(localized: "hello_world") |
| 162 | // or |
| 163 | label.text = NSLocalizedString("hello_world", comment: "Greeting") |
| 164 | ``` |
| 165 | |
| 166 | ## Best Practices |
| 167 | |
| 168 | ### Key Naming Conventions |
| 169 | ``` |
| 170 | // Good: Descriptive, hierarchical |
| 171 | "settings.appearance.theme" |
| 172 | "onboarding.step1.title" |
| 173 | "error.network.connection_failed" |
| 174 | |
| 175 | // Avoid: Vague or hardcoded text as key |
| 176 | "button1" |
| 177 | "Hello, World!" |
| 178 | ``` |
| 179 | |
| 180 | ### Comments for Translators |
| 181 | ```swift |
| 182 | String(localized: "delete_confirmation", |
| 183 | comment: "Alert message asking user to confirm deletion") |
| 184 | ``` |
| 185 | |
| 186 | ### Formatting |
| 187 | ```swift |
| 188 | // Numbers - Use FormatStyle |
| 189 | Text(price, format: .currency(code: "USD")) |
| 190 | |
| 191 | // Dates - Use FormatStyle |
| 192 | Text(date, format: .dateTime.month().day()) |
| 193 | |
| 194 | // Lists - Use ListFormatStyle |
| 195 | Text(items, format: .list(type: .and)) |
| 196 | ``` |
| 197 | |
| 198 | ### RTL Support |
| 199 | ```swift |
| 200 | // Automatic with SwiftUI |
| 201 | // For manual layout adjustments: |
| 202 | .environment(\.layoutDirection, .rightToLeft) |
| 203 | ``` |
| 204 | |
| 205 | ## Testing |