localize-ios
Localize Swift
Localize UIKit Views and ViewControllers and SwiftUI Views: extract hardcoded strings, generate consistent keys, replace literals with the correct Swift API, and create or update the .xcstrings String Catalog.
Workflow
1. Check xcstrings-tool
This step is a hard gate. Do not read the target file, extract strings, propose keys, or take any other action until this step reaches a terminal outcome. The workflow does not advance until one of the two outcomes below is confirmed.
Search for xcstrings-tool in Package.swift and for XCStringsToolPlugin in project.pbxproj.
Outcome A — Already installed: note it and move to step 2.
Outcome B — Not installed: inform the user it is not present, explain the benefit (compile-time key safety), and ask: "Would you like to install xcstrings-tool before continuing, or proceed without it?" Then stop and wait.
- If the user says no / skip: note that
String(localized:)will be used throughout, then move to step 2. - If the user says yes: follow the installation steps in
references/xcstrings-tool.md → Installation, ask them to build (Cmd+B), then verifyXCStringsToolPluginappears inproject.pbxproj. If not found, inform the user the plugin is still missing and do not advance. Only move to step 2 once confirmed present.
2. Read the target file
Read the Swift file the user points to. Classify it as one of:
- View layer — UIKit ViewController, UIView subclass, SwiftUI View
- ViewModel / Presenter — class or struct that owns display-intent properties (e.g.
title,message,buttonLabel) consumed by a view - Helper / Formatter / Enum — produces strings that eventually reach the UI (e.g. an enum with a
var title: Stringswitch, a date formatter returning display text)
The classification affects the replacement API (see step 6) but all three types can contain strings that need localization.
3. Extract hardcoded strings
Find all raw string literals that represent user-visible text. For ViewModel and helper files, apply the data-flow heuristic in references/key-naming.md → User-Facing Strings in ViewModels and Helper Classes to determine whether each string reaches the UI. See the full exclusion list there as well.
Present all candidates to the user before making changes.
4. Propose localization keys
Use camelCase — featureNameComponentNameDescription. Derive the prefix from the file name or feature folder.
| Source string | Proposed key |
|---|---|
"Screen title" |
featureTitle |
"Always ask" |
featureAlwaysAskToggleLabel |
"Done" |
featureDoneButtonLabel |
"No results" |
featureEmptyStateMessage |
See references/key-naming.md for naming rules and conflict resolution. Present the full key list to the user and confirm before making any changes. Accept corrections.
5. Update the .xcstrings file
See references/xcstrings-format.md for exact JSON structure.
-
Search the project for all
*.xcstringsfiles.- If more than one is found, ask the user which file to add the new keys to before proceeding.
- If exactly one is found, use it directly.
- If none is found, create one (see step 2).
-
Creating
Localizable.xcstrings— locate theResourcesfolder in the main target. Identify it by the presence of any of:*.xcassetsdirectories,.mp4files,.jsonfiles, or other static resource files. InsideResources, create aLocalization/subfolder and writeLocalizable.xcstringsthere using the base structure fromreferences/xcstrings-format.md:Resources/ └── Localization/ └── Localizable.xcstringsThen immediately register it in
project.pbxprojby running the bundled script:swift sh .claude/skills/localize-ios/scripts/add_to_xcodeproj.swift \ "path/to/App.xcodeproj" \ "path/to/Resources/Localization/Localizable.xcstrings" \ --group LocalizationThe script will:
- Detect the main app target automatically (by
productType = "com.apple.product-type.application") - Create a
LocalizationPBXGroup if it doesn't exist, nested under the parentResourcesgroup - Add the file reference with
path = Localizable.xcstrings(the group'spathhandles the directory) - Add the build file to the correct target's
PBXResourcesBuildPhase
Verify the script output confirms the target name, file reference UUID, and build file UUID.
Unless the user explicitly requests otherwise, the
.xcstringsfile must always belong to the main app target. Use--target "TargetName"to override if needed. - Detect the main app target automatically (by
-
Add each new key as an entry under
"strings"with:"extractionState": "manual"- A
"comment"describing context for translators - The source string as the English value with
"state": "new"
-
Check for existing translations. Search
project.pbxprojfor theknownRegionsarray to detect all languages configured in the project. Do not rely on inspecting the.xcstringsfile itself. For each language code found inknownRegionsother thanenandBase:- Add a
"localizations"entry for that language on every new key - Provide the actual translation — do not copy the English value
- Set
"state": "translated" - If you are not confident in the translation accuracy, set
"state": "needs_review"and add a note in the report
- Add a
6. Replace strings in the Swift file
Apply API selection in this order:
- xcstrings-tool installed → use typed API (
.localizable(...)) everywhere in the target. - xcstrings-tool not installed → use
String(localized:). - Cross-target exception: file belongs to a target without
XCStringsToolPlugin→ useString(localized:, table:).
See references/xcstrings-tool.md → Usage by Context for code patterns covering UIKit, SwiftUI, and switch statements.
7. Report results
After all changes, output:
- A table of replaced strings → keys
- Path to the created/updated
.xcstringsfile - xcstrings-tool recommendation if not installed
- Next steps: add translations in Xcode's String Catalog editor, then build to regenerate typed accessors
Examples
Positive Trigger
User: "Localize ProfileViewController.swift"
Expected behavior: Read the file, extract all hardcoded user-facing strings, propose camelCase keys, confirm with the user, replace strings with String(localized:), and create/update Localizable.xcstrings.
Non-Trigger
User: "Fix the layout bug in ProfileViewController where the button is clipped."
Expected behavior: Do not use this skill. Investigate and fix the layout issue directly without invoking the localization workflow.
Troubleshooting
Switch statement strings not replaced
- Error: Raw string literals inside switch cases remain hardcoded after running the workflow.
- Cause: Each switch case returns a String and must be wrapped individually — there is no single call site.
- Solution: Replace each case's string literal with
String(localized: "key")or.localizable(.key)one by one.
.xcstrings file not found
- Error: No
Localizable.xcstringsfile exists in the project. - Cause: The project has not been localized yet.
- Solution: Create
Resources/Localization/Localizable.xcstringsusing the base structure fromreferences/xcstrings-format.md, then runscripts/add_to_xcodeproj.swift(viaswift sh) to register it inproject.pbxproj. Both steps are required — the file must exist on disk AND be referenced in the project.
.xcstrings file created but missing in Xcode
- Error:
Localizable.xcstringsexists on disk but does not appear in Xcode's project navigator and is not bundled. - Cause: The file was written to disk but
project.pbxprojwas not updated. - Solution: Run
scripts/add_to_xcodeproj.swift(viaswift sh) with the correct.xcodeprojpath and file path. Confirm the script output shows the target and group where the file was added, then reopen the project in Xcode.
xcstrings-tool typed accessors missing after adding keys
- Error: After adding keys to
.xcstrings,.localizable(...)properties are not available. - Cause: xcstrings-tool runs as a build-time plugin — it regenerates Swift types only when the project builds.
- Solution: Build the project (Cmd+B in Xcode) to trigger code generation. If the types still do not appear, verify the plugin is added to the app target's Build Phases.
.xcstrings file added to wrong target
- Error:
Localizable.xcstringsis registered inproject.pbxprojbut xcstrings-tool does not generate typed accessors, or the strings are not found at runtime. - Cause: The file was added to an extension target's
PBXResourcesBuildPhaseinstead of the main app target's. - Solution: The
add_to_xcodeproj.swiftscript automatically finds the main app target byproductType = .application. If you need a specific target, use--target "TargetName". For manual fixes, move the build file entry from the extension target'sPBXResourcesBuildPhaseto the main app target's phase.
Localizable.xcstrings registered under wrong group in Xcode navigator
- Error: Xcode build error "The file 'Localizable.xcstrings' couldn't be opened because there is no such file" even though the file exists on disk.
- Cause:
scripts/add_to_xcodeproj.swiftcreated theLocalizationPBXGroup but nested it under the wrong parent group (e.g.UIinstead ofResources). Xcode resolves the file path by walking the group chain, so the wrong parent causes the resolved path to differ from the actual disk path. - Solution: Verify in
project.pbxprojthat theLocalizationgroup appears in thechildrenarray of theResourcesgroup (not any other group). If it is under the wrong parent, remove the entry from the wrong group'schildrenarray and add it to theResourcesgroup'schildrenarray.
Key naming conflict with existing entries
- Error: A proposed key already exists in
.xcstringswith a different source string. - Cause: The same key was reused across different UI contexts.
- Solution: Make the key more specific by adding more context segments, e.g.
featureConfirmButtonLabelinstead offeatureLabel.