This project uses SwiftGen to automatically generate Swift code from Localizable.xcstrings files with a hierarchical organization strategy.
We use a view-then-component hierarchical structure with lowercase-dash-dot notation:
view-name.component.property.accessibility.type
shared.component.property.accessibility.type
View-Specific Keys:
link-detail.edit-link.label→L10n.LinkDetail.EditLink.labellink-detail.edit-link.accessibility.label→L10n.LinkDetail.EditLink.Accessibility.labelcreate-link.title→L10n.CreateLink.titlelink-lists.no-lists-title→L10n.LinkLists.noListsTitle
Shared Components:
shared.button.cancel.label→L10n.Shared.Button.Cancel.labelshared.error.network.description→L10n.Shared.Error.Network.descriptionshared.form.title.accessibility.hint→L10n.Shared.Form.Title.Accessibility.hintshared.action.delete→L10n.Shared.Action.delete
View-Specific Patterns:
app.*- App-level stringscreate-link.*- Link creation interfacecreate-list.*- List creation interfacelink-detail.*- Link detail viewlink-lists.*- Lists overviewlink-list-detail.*- Individual list viewsearch.*- Search functionality
Shared Component Patterns:
shared.button.*- Reusable buttons (Save, Cancel, Done, Delete, Edit)shared.form.*- Form fields (Title, Name, URL)shared.error.*- Error messages and recoveryshared.action.*- Context menu/swipe actions (Edit, Delete, Pin, Share)shared.item.*- List/link item accessibilityshared.color-picker.*- Color selection interfaceshared.symbol-picker.*- Symbol selection interfaceshared.qr-code.*- QR code generation and displayshared.toast.*- Toast notificationsshared.delete-confirmation.*- Deletion confirmation dialogsshared.persistence.*- Persistence error messages
The localization system works in three steps:
- Convert xcstrings to JSON: Using
plutilto convert the Xcode strings catalog to JSON format - Convert JSON to strings: Using SwiftGen with custom template to create
.stringsfile - Convert strings to Swift: Using SwiftGen to generate structured Swift enum
The generated L10n enum follows the dot notation in your string keys to create nested enums:
// View-specific examples:
L10n.LinkDetail.EditLink.label // "Edit"
L10n.LinkDetail.EditLink.Accessibility.label // "Edit link"
L10n.CreateLink.title // "New Link"
// Shared component examples:
L10n.Shared.Button.Cancel.label // "Cancel"
L10n.Shared.Error.Network.description // "Network Error: %@"
L10n.Shared.Form.Title.Accessibility.hint // "Enter the link title"
L10n.Shared.Action.delete // "Delete"Use View-Specific Keys When:
- The string is unique to a particular view or feature
- The context matters for translation
- The string has view-specific wording
Use Shared Keys When:
- The string appears in multiple views
- It's a common UI element (buttons, form fields, errors)
- It's a standard action or message
For accessibility, always follow this pattern:
component.accessibility.label // What the element is
component.accessibility.hint // What it does or how to use it
Examples:
// Button with both label and hint
L10n.LinkDetail.EditLink.Accessibility.label // "Edit link"
L10n.LinkDetail.EditLink.Accessibility.hint // "Edit link properties"
// Form field with both label and hint
L10n.Shared.Form.Title.Accessibility.label // "Title field"
L10n.Shared.Form.Title.Accessibility.hint // "Enter the link title"Run the generation script manually:
./Scripts/generate-localization.shThe generation is included in the main make generate command:
make generate # Generates licenses, version info, AND localization
make generate-localization # Generates only localizationWhen adding new features:
- Plan your keys: Decide if strings are view-specific or shared
- Follow the hierarchy: Use the established patterns
- Add to Xcode: Add strings to
Sources/Resources/Localizable.xcstringsusing Xcode's String Catalog editor - Generate: Run
make generate-localization - Use in code: Reference the generated constants:
L10n.YourCategory.yourKey - Build and test: Use
make build-iosto catch any localization issues
├── Scripts/
│ └── generate-localization.sh # Main generation script
├── Templates/
│ ├── en-strings.stencil # Template: xcstrings JSON → strings
│ └── l21strings.stencil # Template: strings → Swift enum
├── Generated/ # Temporary files (gitignored)
│ └── generated-en.strings # Intermediate strings file
├── Sources/Resources/
│ └── Localizable.xcstrings # Source strings catalog
└── Sources/Utils/
└── Localization.swift # Generated Swift code
- Converts xcstrings JSON format to traditional
.stringsformat - Filters out keys that don't make valid Swift identifiers
- Handles both regular strings and plural variations
- Creates nested Swift enums based on dot notation in keys
- Generates functions for parameterized strings
- Includes fallback values for safety
- Follows SwiftGen best practices for localization
- Type Safety: Compile-time checking of localization keys
- Auto-completion: IDE support for all localized strings
- Structured Organization: Nested enums mirror your string key hierarchy
- Consistency: Enforced naming patterns prevent duplication
- Automatic Updates: No manual maintenance of localization constants
- Accessibility First: Built-in patterns for accessibility labels and hints
- Shared Components: Reusable strings reduce duplication and translation costs