Localize ios

From ravnhq/ai-toolkit · View interactive version

Localize ios is an AI agent skill from the GitHub repository ravnhq/ai-toolkit. Localizes UIKit Views and ViewControllers and SwiftUI Views. Extracts hardcoded text, generates camelCase keys, replaces literals with String(localized:) or LocalizedStringKey, and creates or updates Localizable.xcstrings. Use when: (1) localizing a UIKit or SwiftUI file, (2) extracting hardcoded st

How to use this skill

Skill file

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.

Overview

String Catalogs (.xcstrings, Xcode 15+) are the Apple-recommended localization format. This skill guides extraction of hardcoded strings, generation of camelCase keys, and replacement with typed APIs (String(localized:) or xcstrings-tool's .localizable(...)).

Rules

See rules index for detailed patterns covering:

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.

2. Read the target file

Read the Swift file the user points to. Classify it as one of:

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.

  1. Search the project for all *.xcstrings files.
  1. Creating Localizable.xcstrings — locate the Resources folder in the main target. Identify it by the presence of any of: *.xcassets directories, .mp4 files, .json files, or other static resource files. Inside Resources, create a Localization/ subfolder and write Localizable.xcstrings there using the base structure from references/xcstrings-format.md:

```

Resources/

└── Localization/

└── Localizable.xcstrings

```

Then immediately register it in project.pbxproj by running the bundled script:

```bash

swift sh .claude/skills/localize-ios/scripts/add_to_xcodeproj.swift \

"path/to/App.xcodeproj" \

"path/to/Resources/Localization/Localizable.xcstrings" \

--group Localization

```

The script will:

Verify the script output confirms the target name, file reference UUID, and build file UUID.

Unless the user explicitly requests otherwise, the .xcstrings file must always belong to the main app target. Use --target "TargetName" to override if needed.

  1. Add each new key as an entry under "strings" with:
  1. Check for existing translations. Search project.pbxproj for the knownRegions array to detect all languages configured in the project. Do not rely on inspecting the .xcstrings file itself. For each language code found in knownRegions other than en and Base:

6. Replace strings in the Swift file

Apply API selection in this order:

  1. xcstrings-tool installed → use typed API (.localizable(...)) everywhere in the target.
  2. xcstrings-tool not installed → use String(localized:).
  3. Cross-target exception: file belongs to a target without XCStringsToolPlugin → use String(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:

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

.xcstrings file not found

.xcstrings file created but missing in Xcode

xcstrings-tool typed accessors missing after adding keys

.xcstrings file added to wrong target

Localizable.xcstrings registered under wrong group in Xcode navigator

Key naming conflict with existing entries

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.