Skip to content

Commit a65f289

Browse files
authored
Merge pull request #6 from WendellXY/feature/edit-command
feat(cli): add edit command for in-place localization file modifications
2 parents 9823102 + c63ede5 commit a65f289

7 files changed

Lines changed: 1279 additions & 212 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Universal localization toolkit: library + CLI for Apple/Android/CSV/TSV.
44

55
- Library crate (`langcodec`): parse, write, convert, merge with a unified model
6-
- CLI crate (`langcodec-cli`): convert, merge, view, stats, debug
6+
- CLI crate (`langcodec-cli`): convert, merge, view, stats, debug, edit
77

88
---
99

@@ -57,6 +57,7 @@ This is a `0.4.0` release available on [crates.io](https://crates.io/crates/lang
5757
### CLI Highlights
5858

5959
- Convert: `langcodec convert -i input.strings -o strings.xml`
60+
- Edit (add/update/remove): `langcodec edit set -i 'locales/**/*.strings' -k welcome -v "Hello"` (use `--dry-run` to preview)
6061
- View: `langcodec view -i strings.xml --full`
6162
- Stats (JSON): `langcodec stats -i Localizable.xcstrings --json`
6263
- See full options: langcodec-cli/README.md#stats
@@ -88,6 +89,7 @@ This is a `0.4.0` release available on [crates.io](https://crates.io/crates/lang
8889
- All commands support Apple `.strings`, `.xcstrings`, Android `strings.xml`, and CSV.
8990
- The convert command also supports JSON files with key-value pairs.
9091
- The CLI will error if you try to merge files of different formats.
92+
- Edit supports multiple inputs and glob patterns. When multiple inputs are provided, edits are applied in-place and `--output` is not allowed.
9193
- Android path inference: `values/strings.xml` (no qualifier) defaults to English (`en`).
9294
- When converting to `.xcstrings`, if `source_language` or `version` metadata is missing, the CLI defaults them to `en` and `1.0` respectively (overridable via flags).
9395

langcodec-cli/README.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# langcodec-cli (Command Line)
22

3-
Universal CLI for converting, inspecting, and merging localization files.
3+
Universal CLI for converting, inspecting, merging, and editing localization files.
44

55
- Formats: Apple `.strings`, `.xcstrings`, Android `strings.xml`, CSV, TSV
6-
- Commands: convert, merge, view, stats, debug
6+
- Commands: convert, merge, view, stats, debug, edit
77

88
## Install
99

@@ -51,11 +51,50 @@ Shows per-language totals, counts by status, and completion percent (excludes Do
5151
langcodec debug -i input.strings --lang en -o output.json
5252
```
5353

54+
### edit
55+
56+
Unified in-place editing (add/update/remove) across one or many files.
57+
58+
Basics:
59+
60+
```sh
61+
# Add or update a key
62+
langcodec edit set -i en.strings -k welcome -v "Hello" --status translated --comment "Shown on home"
63+
64+
# Remove a key (omit or empty value)
65+
langcodec edit set -i en.strings -k welcome
66+
langcodec edit set -i en.strings -k welcome -v ""
67+
68+
# Multiple files or globs (quote patterns)
69+
langcodec edit set -i 'locales/**/*.strings' -k app_name -v "My App"
70+
langcodec edit set -i a.strings -i b.strings -k welcome -v "Hello"
71+
72+
# Preview only
73+
langcodec edit set -i en.strings -k welcome -v "Hello" --dry-run
74+
75+
# Write to a different file (single input only)
76+
langcodec edit set -i en.strings -k welcome -v "Hello" -o out.strings
77+
```
78+
79+
Options:
80+
81+
- --inputs/-i: One or more input files. Supports glob patterns when quoted.
82+
- --lang/-l: Language code (required when an input contains multiple languages).
83+
- --key/-k: Entry key to modify.
84+
- --value/-v: New value. If omitted or empty, the entry is removed.
85+
- --comment: Optional translator note.
86+
- --status: translated|needs_review|new|do_not_translate|stale.
87+
- --output/-o: Optional output path. Not allowed with multiple inputs.
88+
- --dry-run: Print what would change and exit without writing.
89+
- --continue-on-error: Process all inputs; report failures at the end (non-zero exit if any fail).
90+
91+
Supported formats: .strings, .xml (Android), .xcstrings, .csv, .tsv. Custom JSON/YAML/.langcodec edit is currently not enabled.
92+
5493
## Notes
5594

5695
- Android plurals `<plurals>` are supported.
5796
- Language inference: `en.lproj/Localizable.strings`, `values-es/strings.xml`, base `values/``en` by default.
58-
- Globbing: use quotes for patterns in merge (e.g., `'**/*.xml'`).
97+
- Globbing: use quotes for patterns in merge and edit (e.g., `'**/*.xml'`).
5998

6099
## License
61100

0 commit comments

Comments
 (0)