xcstrings-cli 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +112 -86
  2. package/dist/index.js +1328 -1002
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -9,18 +9,20 @@ We also provide a Custom GPT that can help you generate translations and output
9
9
  ## Installation
10
10
 
11
11
  1. Install xcstrings-cli using npm:
12
+
12
13
  ```bash
13
14
  npm install -g xcstrings-cli
14
15
  ```
15
16
 
16
17
  This will install the `xcs` command globally.
17
18
 
18
- 2. Create a configuration file for your project by running:
19
+ 2. Create a [configuration file](#configuration-file) for your project by running:
20
+
19
21
  ```bash
20
22
  xcs init
21
23
  ```
22
24
 
23
- This will ask you some questions and create an `xcstrings-cli.json` file in the current directory.
25
+ This will ask you some questions and create an `xcstrings-cli.yaml` file in the current directory.
24
26
 
25
27
  ## Usage
26
28
 
@@ -102,7 +104,7 @@ xcs remove --languages ja zh-Hans
102
104
 
103
105
  **List supported languages:**
104
106
 
105
- If `xcodeprojPaths` is configured, this command lists languages from your Xcode project (knownRegions) and excludes `Base`. If `xcodeprojPaths` is not configured, it lists languages observed in the xcstrings file.
107
+ If `xcodeprojPaths` is configured, this command lists languages from your Xcode project (knownRegions) and excludes `Base`. Otherwise, it lists languages appeared in the xcstrings file.
106
108
 
107
109
  ```bash
108
110
  xcs languages
@@ -152,21 +154,31 @@ xcs strings --format "[{{language}}] {{key}} => {{text}}"
152
154
  # ... etc.
153
155
  ```
154
156
 
157
+ **Export strings to _xcstrings_ or traditional _strings_ files:**
158
+
159
+ ```bash
160
+ # Export all strings to Test.xcstrings
161
+ xcs export Test.xcstrings
162
+
163
+ # Export keys starting with 'good' to Output.strings in language specific lproj folders
164
+ xcs export --key good* --output strings Output
165
+ ```
166
+
155
167
  You can use `xcs --help` or `xcs <sub-command> --help` to see the list of commands and options.
156
168
 
157
169
  ## Commands
158
170
 
159
171
  **Global options:**
160
172
 
161
- * `--config`: `string` (Optional)
162
- * The custom config file path. If not specified, `xcs` will look for `xcstrings-cli.json` or `xcstrings-cli.json5` in the current folder or its parent folders until the root.
163
- * `--help, -h`: `boolean` (Optional)
164
- * Show help.
165
- * `--path`: `string` (Optional)
166
- * The xcstrings file path. Defaults to `Localizable.xcstrings` in the current directory, or to the first `xcstringsPaths` entry in the config when present.
167
- * You can also specify the alias you set in the config file. (`xcstringsPaths` entry with `alias` field)
168
- * `--version, -v`: `boolean` (Optional)
169
- * Show version.
173
+ - `--config`: `string` (Optional)
174
+ - The custom config file path. If not specified, `xcs` will look for `xcstrings-cli.json` or `xcstrings-cli.json5` in the current folder or its parent folders until the root.
175
+ - `--help, -h`: `boolean` (Optional)
176
+ - Show help.
177
+ - `--path`: `string` (Optional)
178
+ - The xcstrings file path. Defaults to `Localizable.xcstrings` in the current directory, or to the first `xcstringsPaths` entry in the config when present.
179
+ - You can also specify the alias you set in the config file. (`xcstringsPaths` entry with `alias` field)
180
+ - `--version, -v`: `boolean` (Optional)
181
+ - Show version.
170
182
 
171
183
  ### `add` command
172
184
 
@@ -174,36 +186,32 @@ Adds/updates one or more strings to the xcstrings file.
174
186
 
175
187
  **`add` command options:**
176
188
 
177
- * `--comment`: `string` (Optional)
178
- * The comment for the string to add, intended for translators.
179
- * `--interactive, -i`: `boolean` (Optional)
180
- * Start interactive mode to add strings.
181
- * This is useful when you don't want to record a huge command to your terminal history.
182
- * `--key, -k`: `string` (Required unless `--strings` contains one or more keys)
183
- * The key of the string to add.
184
- * `--language, -l`: `string` (Optional)
185
- * The language of the string provided with `--text`.
186
- * Ignored if `--text` is not provided.
187
- * If not specified, it uses the source language defined as `sourceLanguage` in the xcstrings file.
188
- * Validation follows `missingLanguagePolicy`: `skip` requires the language to be supported; `include` allows any language.
189
- * `--state`: `string` (Optional, default: `translated`)
190
- * Values applied to single-key and multi-key adds: `translated`, `needs_review`, `new`, `stale`. If omitted, strings default to `translated`.
191
- * Multi-key payloads can also set per-language states with `{ state, value }`; string shorthand is treated as `translated`.
192
- * State meanings:
193
- * `translated`: The string is translated and ready to use.
194
- * `needs_review`: The string needs review by a translator.
195
- * `new`: The string is newly added and not yet translated.
196
- * `stale`: The string is outdated and may need re-translation.
197
- * `--strings`: `string` (Optional)
198
- * Translation-including JSON or YAML for the key. Pass inline JSON, or provide the flag without a value to read it from stdin (heredoc/pipe).
199
- * The format is determined by `--strings-format`.
200
- * `--strings-format`: `string` (Optional, default: `auto`)
201
- * The format of the data provided with `--strings`. Options are:
202
- * `auto`: Auto-detect format based on content.
203
- * `yaml`: YAML format. (It uses `js-yaml` internally.)
204
- * `json`: JSON format. (It uses `json5` internally.)
205
- * `--text`: `string` (Optional)
206
- * The string value for the language. If omitted, the key is created without a localization for the default language.
189
+ - `--comment`: `string` (Optional)
190
+ - The comment for the string to add, intended for translators.
191
+ - `--interactive, -i`: `boolean` (Optional)
192
+ - Start interactive mode to add strings.
193
+ - This is useful when you don't want to record a huge command to your terminal history.
194
+ - `--key, -k`: `string` (Required unless `--strings` contains one or more keys)
195
+ - The key of the string to add.
196
+ - `--language, -l`: `string` (Optional)
197
+ - The language of the string provided with `--text`.
198
+ - Ignored if `--text` is not provided.
199
+ - If not specified, it uses the source language defined as `sourceLanguage` in the xcstrings file.
200
+ - Validation follows `missingLanguagePolicy`: `skip` requires the language to be supported; `include` allows any language.
201
+ - `--state`: `string` (Optional, default: `translated`)
202
+ - Values applied to single-key and multi-key adds: `translated`, `needs_review`, `new`, `stale`. If omitted, strings default to `translated`.
203
+ - Multi-key payloads can also set per-language states with `{ state, value }`; string shorthand is treated as `translated`.
204
+ - Available states: `translated`, `needs_review`, `new`, `stale`
205
+ - `--strings`: `string` (Optional)
206
+ - Translation-including JSON or YAML for the key. Pass inline JSON, or provide the flag without a value to read it from stdin (heredoc/pipe).
207
+ - The format is determined by `--strings-format`.
208
+ - `--strings-format`: `string` (Optional, default: `auto`)
209
+ - The format of the data provided with `--strings`. Options are:
210
+ - `auto`: Auto-detect format based on content.
211
+ - `yaml`: YAML format.
212
+ - `json`: JSON format. JSON5 is also supported.
213
+ - `--text`: `string` (Optional)
214
+ - The string value for the language. If omitted, the key is created without a localization for the default language.
207
215
 
208
216
  ### `remove` command
209
217
 
@@ -211,12 +219,12 @@ Removes strings from the xcstrings file based on the specified filter options.
211
219
 
212
220
  **`remove` command options:**
213
221
 
214
- * `--dry-run, -n`: `boolean` (Optional, default: `false`)
215
- * If set to `true`, `xcs` will only show what would be removed without actually removing anything.
216
- * `--key, -k`: `string` (Optional if `languages` is specified)
217
- * The key of the string to remove. If not specified, xcstrings-cli will remove all strings for the specified languages.
218
- * `--languages, -l`: `string[]` (Optional if `key` is specified)
219
- * The languages to remove. If not specified, `xcs` will remove the string for all languages.
222
+ - `--dry-run, -n`: `boolean` (Optional, default: `false`)
223
+ - If set to `true`, `xcs` will only show what would be removed without actually removing anything.
224
+ - `--key, -k`: `string` (Optional if `languages` is specified)
225
+ - The key of the string to remove. If not specified, xcstrings-cli will remove all strings for the specified languages.
226
+ - `--languages, -l`: `string[]` (Optional if `key` is specified)
227
+ - The languages to remove. If not specified, `xcs` will remove the string for all languages.
220
228
 
221
229
  ### `strings` command
222
230
 
@@ -224,24 +232,46 @@ Lists strings in the xcstrings file, with optional filtering and formatting.
224
232
 
225
233
  **`strings` commands options:**
226
234
 
227
- * `--format`: `string` (Optional)
228
- * Mustache template for per-localization output. Available variables: `{{language}}`, `{{key}}`, `{{text}}`.
229
- * `--key`, `--key-glob`: `string` (Optional)
230
- * Filter keys by glob pattern. This is the default key filter mode.
231
- * `--key-regex`: `string` (Optional)
232
- * Filter keys by regular expression.
233
- * `--key-substring`: `string` (Optional)
234
- * Filter keys by substring match.
235
- * `--languages, -l`: `string[]` (Optional)
236
- * Include only the specified languages.
237
- * `--text`, `--text-glob`: `string` (Optional)
238
- * Filter translations by glob pattern. This is the default text filter mode.
239
- * `--text-regex`: `string` (Optional)
240
- * Filter translations by regular expression.
241
- * `--text-substring`: `string` (Optional)
242
- * Filter translations by substring match.
243
-
244
- ## Config file
235
+ - `--format`: `string` (Optional)
236
+ - Mustache template for per-localization output. Available variables: `{{language}}`, `{{key}}`, `{{text}}`.
237
+ - `--key`, `--key-glob`: `string` (Optional)
238
+ - Filter keys by glob pattern. This is the default key filter mode.
239
+ - `--key-regex`: `string` (Optional)
240
+ - Filter keys by regular expression.
241
+ - `--key-substring`: `string` (Optional)
242
+ - Filter keys by substring match.
243
+ - `--languages, -l`: `string[]` (Optional)
244
+ - Include only the specified languages.
245
+ - `--text`, `--text-glob`: `string` (Optional)
246
+ - Filter translations by glob pattern. This is the default text filter mode.
247
+ - `--text-regex`: `string` (Optional)
248
+ - Filter translations by regular expression.
249
+ - `--text-substring`: `string` (Optional)
250
+ - Filter translations by substring match.
251
+
252
+ ### `export` command
253
+
254
+ Exports xcstrings to either filtered xcstrings or traditional `.strings` format.
255
+
256
+ **`export` command options:**
257
+
258
+ - `--output, -o`: `string` (Optional, default: `auto`)
259
+ - The output format. Options are:
260
+ - `auto`: Inferred from the output path extension if possible.
261
+ - `xcstrings`: Export to a `.xcstrings` catalog format.
262
+ - `strings`: Export to Apple's traditional `.strings` format generated in `<language>.lproj` directories.
263
+ - `--merge-policy, -m`: `string` (Optional, default: `error`)
264
+ - How to handle existing translation files:
265
+ - `error`: Stop safely if an output file exists.
266
+ - `force`: Clobber and overwrite existing files.
267
+ - `output-first`: Augment existing files, preferring new translations over old ones.
268
+ - `existing-first`: Keep existing translations intact, appending only non-overlapping strings.
269
+ - Filtering options from the `strings` command are also supported:
270
+ - `--key`, `--key-glob`, `--key-regex`, `--key-substring`
271
+ - `--text`, `--text-glob`, `--text-regex`, `--text-substring`
272
+ - `--languages, -l`
273
+
274
+ ## Configuration file
245
275
 
246
276
  Put a config file named `xcstrings-cli` in the project root, using one of the following extensions:
247
277
 
@@ -261,26 +291,24 @@ Here is an example config file in JSON format:
261
291
  "path": "packages/Utils/Sources/Utils/Resources/Localizable.xcstrings"
262
292
  }
263
293
  ],
264
- "xcodeprojPaths": [
265
- "path/to/your/Project.xcodeproj"
266
- ]
294
+ "xcodeprojPaths": ["path/to/your/Project.xcodeproj"]
267
295
  }
268
296
  ```
269
297
 
270
298
  These are the settings you can specify in the config file:
271
299
 
272
- * **missingLanguagePolicy**: `string` (Optional, default: `skip`)
273
- * How to handle translations for languages that are not included in the `xcs languages` output when adding strings. Options are:
274
- * `skip`: Only add translations for languages included in the `xcs languages` output. (Default)
275
- * `include`: Add translations even when they are not recognized by the Xcode project or xcs language list.
276
- * **xcodeprojPaths**: `string[]` (Optional)
277
- * Paths to Xcode project files (`.xcodeproj`) used to detect supported languages.
278
- * If not specified, `xcs` will only check the xcstrings file to detect supported languages.
279
- * **xcstringsPaths**: `string[] | { alias: string, path: string }[]` (Optional)
280
- * Paths to xcstrings files used by `xcs`.
281
- * If only one path is provided, `xcs` will use it as the default xcstrings file.
282
- * If multiple paths are provided, `xcs` will ask you to select an xcstrings file.
283
- * You can also specify an alias, and use it with the `--path` option.
300
+ - **missingLanguagePolicy**: `string` (Optional, default: `skip`)
301
+ - How to handle translations for languages that are not included in the `xcs languages` output when adding strings. Options are:
302
+ - `skip`: Only add translations for languages included in the `xcs languages` output. (Default)
303
+ - `include`: Add translations even when they are not recognized by the Xcode project or xcs language list.
304
+ - **xcodeprojPaths**: `string[]` (Optional)
305
+ - Paths to Xcode project files (`.xcodeproj`) used to detect supported languages.
306
+ - If not specified, `xcs` will only check the xcstrings file to detect supported languages.
307
+ - **xcstringsPaths**: `(string | { alias: string; path: string })[]` (Optional)
308
+ - Paths to xcstrings files used by `xcs`.
309
+ - If only one path is provided, `xcs` will use it as the default xcstrings file.
310
+ - If multiple paths are provided, `xcs` will ask you to select an xcstrings file.
311
+ - You can also specify an alias, and use it with the `--path` option.
284
312
 
285
313
  ## Practical use cases
286
314
 
@@ -310,10 +338,9 @@ Languages: ja, zh-Hans
310
338
  No comments needed.
311
339
  ```
312
340
 
313
- Then the Custom GPT will generate an `xcs add` command like this:
341
+ Then the Custom GPT will generate YAML like this:
314
342
 
315
- ```bash
316
- xcs add --strings << EOF
343
+ ```yaml
317
344
  closeAction:
318
345
  translations:
319
346
  en: Close
@@ -324,10 +351,9 @@ detailsAction:
324
351
  en: Details
325
352
  ja: 詳細
326
353
  zh-Hans: 详情
327
- EOF
328
354
  ```
329
355
 
330
- Finally, copy the generated command and run it in your terminal to add the translations to your xcstrings file.
356
+ Finally, copy the generated YAML and run `xcs add -i` to add the translations to your xcstrings file via interactive mode.
331
357
 
332
358
  ## Q&A
333
359