xcstrings-cli 2.5.1 → 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 +130 -88
  2. package/dist/index.js +1944 -1548
  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
 
@@ -28,7 +30,7 @@ We also provide a Custom GPT that can help you generate translations and output
28
30
 
29
31
  ```bash
30
32
  # Add with key, comment, and default language string
31
- xcs add --key greeting --comment "A greeting message." --string "Hello, World."
33
+ xcs add --key greeting --comment "A greeting message." --text "Hello, World."
32
34
 
33
35
  # Add with key, comment, and translations YAML via heredoc
34
36
  xcs add \
@@ -52,6 +54,9 @@ xcs add \
52
54
  }
53
55
  EOF
54
56
 
57
+ # Start interactive mode to add translations using `$EDITOR` environment variable (e.g. `vim`)
58
+ xcs add -i
59
+
55
60
  # Add translations via file
56
61
  xcs add \
57
62
  --key greeting \
@@ -99,7 +104,7 @@ xcs remove --languages ja zh-Hans
99
104
 
100
105
  **List supported languages:**
101
106
 
102
- 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.
103
108
 
104
109
  ```bash
105
110
  xcs languages
@@ -149,94 +154,136 @@ xcs strings --format "[{{language}}] {{key}} => {{text}}"
149
154
  # ... etc.
150
155
  ```
151
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
+
152
167
  You can use `xcs --help` or `xcs <sub-command> --help` to see the list of commands and options.
153
168
 
154
169
  ## Commands
155
170
 
156
- ### Global options
171
+ **Global options:**
157
172
 
158
- * `--help, -h`: `boolean` (Optional)
159
- * Show help.
160
- * `--version, -v`: `boolean` (Optional)
161
- * Show version.
162
- * `--config`: `string` (Optional)
163
- * 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.
164
- * `--path`: `string` (Optional)
165
- * The xcstrings file path. Defaults to `Localizable.xcstrings` in the current directory, or to the first `xcstringsPaths` entry in the config when present.
166
- * You can also specify the alias you set in the config file. (`xcstringsPaths` entry with `alias` field)
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.
167
182
 
168
183
  ### `add` command
169
184
 
170
185
  Adds/updates one or more strings to the xcstrings file.
171
186
 
172
- * `--key, -k`: `string` (Required unless `--strings` contains one or more keys)
173
- * The key of the string to add.
174
- * `--language, -l`: `string` (Optional)
175
- * The language of the string provided with `--text`.
176
- * Ignored if `--text` is not provided.
177
- * If not specified, it uses the source language defined as `sourceLanguage` in the xcstrings file.
178
- * Validation follows `missingLanguagePolicy`: `skip` requires the language to be supported; `include` allows any language.
179
- * `--text`: `string` (Optional)
180
- * The string value for the language. If omitted, the key is created without a localization for the default language.
181
- * `--state`: `string` (Optional, default: `translated`)
182
- * Values applied to single-key and multi-key adds: `translated`, `needs_review`, `new`, `stale`. If omitted, strings default to `translated`.
183
- * Multi-key payloads can also set per-language states with `{ state, value }`; string shorthand is treated as `translated`.
184
- * State meanings:
185
- * `translated`: The string is translated and ready to use.
186
- * `needs_review`: The string needs review by a translator.
187
- * `new`: The string is newly added and not yet translated.
188
- * `stale`: The string is outdated and may need re-translation.
189
- * `--strings`: `string` (Optional)
190
- * 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).
191
- * The format is determined by `--strings-format`.
192
- * `--strings-format`: `string` (Optional, default: `auto`)
193
- * The format of the data provided with `--strings`. Options are:
194
- * `auto`: Auto-detect format based on content.
195
- * `yaml`: YAML format. (It uses `js-yaml` internally.)
196
- * `json`: JSON format. (It uses `json5` internally.)
197
- * `--comment`: `string` (Optional)
198
- * The comment for the string to add, intended for translators.
187
+ **`add` command options:**
188
+
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.
199
215
 
200
216
  ### `remove` command
201
217
 
202
218
  Removes strings from the xcstrings file based on the specified filter options.
203
219
 
204
- * `--key, -k`: `string` (Optional if `languages` is specified)
205
- * The key of the string to remove. If not specified, xcstrings-cli will remove all strings for the specified languages.
206
- * `--languages, -l`: `string[]` (Optional if `key` is specified)
207
- * The languages to remove. If not specified, `xcs` will remove the string for all languages.
208
- * `--dry-run, -n`: `boolean` (Optional, default: `false`)
209
- * If set to `true`, `xcs` will only show what would be removed without actually removing anything.
220
+ **`remove` command options:**
221
+
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.
210
228
 
211
229
  ### `strings` command
212
230
 
213
231
  Lists strings in the xcstrings file, with optional filtering and formatting.
214
232
 
215
- * `--languages, -l`: `string[]` (Optional)
216
- * Include only the specified languages.
217
- * `--key`, `--key-glob`: `string` (Optional)
218
- * Filter keys by glob pattern. This is the default key filter mode.
219
- * `--key-regex`: `string` (Optional)
220
- * Filter keys by regular expression.
221
- * `--key-substring`: `string` (Optional)
222
- * Filter keys by substring match.
223
- * `--text`, `--text-glob`: `string` (Optional)
224
- * Filter translations by glob pattern. This is the default text filter mode.
225
- * `--text-regex`: `string` (Optional)
226
- * Filter translations by regular expression.
227
- * `--text-substring`: `string` (Optional)
228
- * Filter translations by substring match.
229
- * `--format`: `string` (Optional)
230
- * Mustache template for per-localization output. Available variables: `{{language}}`, `{{key}}`, `{{text}}`.
231
-
232
- ## Config file
233
-
234
- Put an `xcstrings-cli.json5` or `xcstrings-cli.json` file in the project root, and xcs will use it as the config file.
233
+ **`strings` commands options:**
234
+
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
275
+
276
+ Put a config file named `xcstrings-cli` in the project root, using one of the following extensions:
277
+
278
+ - `.json`: JSON format
279
+ - `.json5`: JSON5 format
280
+ - `.yml` `.yaml`: YAML format
235
281
 
236
282
  Here is an example config file in JSON format:
237
283
 
238
284
  ```json
239
285
  {
286
+ "missingLanguagePolicy": "include",
240
287
  "xcstringsPaths": [
241
288
  "Shared/L10n/Localizable.xcstrings",
242
289
  {
@@ -244,27 +291,24 @@ Here is an example config file in JSON format:
244
291
  "path": "packages/Utils/Sources/Utils/Resources/Localizable.xcstrings"
245
292
  }
246
293
  ],
247
- "xcodeprojPaths": [
248
- "path/to/your/Project.xcodeproj"
249
- ],
250
- "missingLanguagePolicy": "include"
294
+ "xcodeprojPaths": ["path/to/your/Project.xcodeproj"]
251
295
  }
252
296
  ```
253
297
 
254
298
  These are the settings you can specify in the config file:
255
299
 
256
- * **xcstringsPaths**: `string[] | { alias: string, path: string }[]` (Optional)
257
- * Paths to xcstrings files used by `xcs`.
258
- * If only one path is provided, `xcs` will use it as the default xcstrings file.
259
- * If multiple paths are provided, `xcs` will ask you to select an xcstrings file.
260
- * You can also specify an alias, and use it with the `--path` option.
261
- * **xcodeprojPaths**: `string[]` (Optional)
262
- * Paths to Xcode project files (`.xcodeproj`) used to detect supported languages.
263
- * If not specified, `xcs` will only check the xcstrings file to detect supported languages.
264
- * **missingLanguagePolicy**: `string` (Optional, default: `skip`)
265
- * How to handle translations for languages that are not included in the `xcs languages` output when adding strings. Options are:
266
- * `skip`: Only add translations for languages included in the `xcs languages` output. (Default)
267
- * `include`: Add translations even when they are not recognized by the Xcode project or xcs language list.
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.
268
312
 
269
313
  ## Practical use cases
270
314
 
@@ -294,10 +338,9 @@ Languages: ja, zh-Hans
294
338
  No comments needed.
295
339
  ```
296
340
 
297
- Then the Custom GPT will generate an `xcs add` command like this:
341
+ Then the Custom GPT will generate YAML like this:
298
342
 
299
- ```bash
300
- xcs add --strings << EOF
343
+ ```yaml
301
344
  closeAction:
302
345
  translations:
303
346
  en: Close
@@ -308,10 +351,9 @@ detailsAction:
308
351
  en: Details
309
352
  ja: 詳細
310
353
  zh-Hans: 详情
311
- EOF
312
354
  ```
313
355
 
314
- 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.
315
357
 
316
358
  ## Q&A
317
359