|
| 1 | +# Xcode .strings Files Configuration |
| 2 | + |
| 3 | +This guide explains how to use Lara CLI with Xcode `.strings` localization files, commonly used in iOS and macOS applications. |
| 4 | + |
| 5 | +## What are .strings Files? |
| 6 | + |
| 7 | +Xcode `.strings` files are the traditional format for storing localized strings in Apple applications. They use a simple key-value pair format organized by locale in `.lproj` directories (e.g., `en.lproj/Localizable.strings`, `fr.lproj/Localizable.strings`). |
| 8 | + |
| 9 | +Lara CLI supports `.strings` files with: |
| 10 | + |
| 11 | +- Simple key-value string pairs |
| 12 | +- C-style comments (`/* ... */`) |
| 13 | +- Escape sequences (`\"`, `\\`, `\n`, `\t`, `\U` unicode) |
| 14 | + |
| 15 | +## Configuration |
| 16 | + |
| 17 | +To configure Xcode `.strings` files in your `lara.yaml`: |
| 18 | + |
| 19 | +```yaml |
| 20 | +files: |
| 21 | + xcode-strings: |
| 22 | + include: |
| 23 | + - "[locale].lproj/Localizable.strings" |
| 24 | + exclude: [] |
| 25 | + lockedKeys: [] |
| 26 | + ignoredKeys: [] |
| 27 | +``` |
| 28 | +
|
| 29 | +> **Note:** The configuration key is `xcode-strings` (not `strings`). Lara CLI automatically maps `.strings` file extensions to this config key. |
| 30 | +> |
| 31 | +> **Important:** Lara CLI uses `[locale].lproj/Localizable.strings` structure (e.g., `en.lproj/Localizable.strings`, `fr.lproj/Localizable.strings`). The `[locale]` placeholder is replaced with the locale code. |
| 32 | + |
| 33 | +### File Path Patterns |
| 34 | + |
| 35 | +#### Standard Structure (Recommended) |
| 36 | + |
| 37 | +```yaml |
| 38 | +files: |
| 39 | + xcode-strings: |
| 40 | + include: |
| 41 | + - "[locale].lproj/Localizable.strings" |
| 42 | + - "[locale].lproj/InfoPlist.strings" |
| 43 | +``` |
| 44 | + |
| 45 | +This follows the structure: |
| 46 | + |
| 47 | +```text |
| 48 | +MyApp/ |
| 49 | + en.lproj/ |
| 50 | + Localizable.strings |
| 51 | + InfoPlist.strings |
| 52 | + fr.lproj/ |
| 53 | + Localizable.strings |
| 54 | + InfoPlist.strings |
| 55 | + es.lproj/ |
| 56 | + Localizable.strings |
| 57 | + InfoPlist.strings |
| 58 | +``` |
| 59 | + |
| 60 | +#### Custom Structure |
| 61 | + |
| 62 | +```yaml |
| 63 | +files: |
| 64 | + xcode-strings: |
| 65 | + include: |
| 66 | + - "Resources/[locale].lproj/Localizable.strings" |
| 67 | +``` |
| 68 | + |
| 69 | +## .strings File Format |
| 70 | + |
| 71 | +### Basic Format |
| 72 | + |
| 73 | +``` |
| 74 | +/* App Name */ |
| 75 | +"app_name" = "My App"; |
| 76 | + |
| 77 | +/* Greeting message */ |
| 78 | +"hello" = "Hello World"; |
| 79 | + |
| 80 | +/* Button labels */ |
| 81 | +"button_submit" = "Submit"; |
| 82 | +"button_cancel" = "Cancel"; |
| 83 | +``` |
| 84 | +
|
| 85 | +Each entry follows the format: `"key" = "value";` |
| 86 | +
|
| 87 | +### Comments |
| 88 | +
|
| 89 | +C-style block comments and single-line comments are supported and preserved during translation: |
| 90 | +
|
| 91 | +``` |
| 92 | +/* Section: Login Screen */ |
| 93 | +"login_title" = "Welcome Back"; |
| 94 | + |
| 95 | +// Username field placeholder |
| 96 | +"login_username" = "Enter your username"; |
| 97 | +``` |
| 98 | +
|
| 99 | +### Escape Sequences |
| 100 | +
|
| 101 | +``` |
| 102 | +"escaped_quotes" = "Say \"Hello\""; |
| 103 | +"newline" = "Line 1\nLine 2"; |
| 104 | +"tab" = "Column 1\tColumn 2"; |
| 105 | +"backslash" = "C:\\Users\\file"; |
| 106 | +"unicode" = "\U00E9"; |
| 107 | +``` |
| 108 | +
|
| 109 | +### Empty Values |
| 110 | +
|
| 111 | +``` |
| 112 | +"empty_key" = ""; |
| 113 | +``` |
| 114 | +
|
| 115 | +## How Lara CLI Handles .strings Files |
| 116 | +
|
| 117 | +### Automatic Processing |
| 118 | +
|
| 119 | +Lara CLI automatically: |
| 120 | +
|
| 121 | +- Extracts key-value pairs from `.strings` files |
| 122 | +- Preserves comments and their association with keys |
| 123 | +- Maintains key ordering from the source file |
| 124 | +- Handles escape sequences correctly |
| 125 | +- Preserves file formatting |
| 126 | +
|
| 127 | +### Key Path Format |
| 128 | +
|
| 129 | +When using `lockedKeys` or `ignoredKeys`, use the key name directly: |
| 130 | +
|
| 131 | +```yaml |
| 132 | +files: |
| 133 | + xcode-strings: |
| 134 | + include: |
| 135 | + - "[locale].lproj/Localizable.strings" |
| 136 | + lockedKeys: |
| 137 | + - "app_name" # Exact key |
| 138 | + - "api_*" # Wildcard pattern |
| 139 | + ignoredKeys: |
| 140 | + - "debug_*" # Ignore all debug keys |
| 141 | +``` |
| 142 | + |
| 143 | +## Complete Example |
| 144 | + |
| 145 | +```yaml |
| 146 | +version: "1.0.0" |
| 147 | + |
| 148 | +project: |
| 149 | + instruction: "iOS app, user-friendly tone" |
| 150 | + |
| 151 | +locales: |
| 152 | + source: en |
| 153 | + target: |
| 154 | + - es |
| 155 | + - fr |
| 156 | + - de |
| 157 | + |
| 158 | +files: |
| 159 | + xcode-strings: |
| 160 | + include: |
| 161 | + - "[locale].lproj/Localizable.strings" |
| 162 | + - "[locale].lproj/InfoPlist.strings" |
| 163 | + exclude: [] |
| 164 | + lockedKeys: |
| 165 | + - "app_name" |
| 166 | + ignoredKeys: |
| 167 | + - "debug_*" |
| 168 | + fileInstructions: |
| 169 | + - path: "[locale].lproj/Localizable.strings" |
| 170 | + instruction: "User-facing messages, friendly tone" |
| 171 | +``` |
| 172 | +
|
| 173 | +## Working with Existing .strings Files |
| 174 | +
|
| 175 | +1. **Run `lara-cli init`** to create your configuration |
| 176 | +2. **Ensure your file paths match the `include` patterns** |
| 177 | +3. **Run `lara-cli translate`** |
| 178 | +4. **Continue developing** - Lara CLI tracks changes via checksums |
| 179 | + |
| 180 | +If your `.strings` files don't exist yet: |
| 181 | + |
| 182 | +1. **Create your source locale file** (e.g., `en.lproj/Localizable.strings`) |
| 183 | +2. **Run `lara-cli translate`** - target locale files are created automatically |
| 184 | + |
| 185 | +## Limitations |
| 186 | + |
| 187 | +- Must use `"key" = "value";` format |
| 188 | +- Keys and values must be double-quoted |
| 189 | +- Each entry must end with a semicolon |
| 190 | +- Files must be organized by locale in `.lproj` directories |
| 191 | + |
| 192 | +## Troubleshooting |
| 193 | + |
| 194 | +### Keys Not Found |
| 195 | + |
| 196 | +- Ensure entries follow the `"key" = "value";` format |
| 197 | +- Check that semicolons are present at the end of each entry |
| 198 | +- Verify the file encoding is UTF-8 |
| 199 | + |
| 200 | +### Comments Missing |
| 201 | + |
| 202 | +- Lara CLI preserves block comments (`/* ... */`) and single-line comments (`// ...`) |
| 203 | +- Comments are associated with the entry that follows them |
| 204 | + |
| 205 | +## Related Documentation |
| 206 | + |
| 207 | +- [Supported Formats](../formats.md) - Overview of all supported file formats |
| 208 | +- [Files Configuration](../files.md) - General file configuration options |
| 209 | +- [Xcode Stringsdict Files](./xcode-stringsdict-files.md) - Plural support for Xcode |
| 210 | +- [Xcode String Catalogs](./xcode-xcstrings-files.md) - Modern Xcode 15+ format |
0 commit comments