Smart i18n maintenance tool: dedupe keys, prune unused translations, and sync nested JSON structures.
npm install langcleanerSave and Apply both being "Submit") and merges them.
t("nav.home")) that don't exist in your JSON yet and adds (if you add --fix) them as empty stubs.
tr.json, de.json, etc.) to match its structure perfectly.
plaintext
+---------+
| Start |
+----+----+
|
v
+-----+-----+
| Dedupe |
+-----+-----+
|
v
+----------+-----------+
| Apply Updates |
+----------+-----------+
|
v
+-------+-------+
| Clean Unused |
+-------+-------+
|
v
+-------+-------+
| Add Missing |
+-------+-------+
|
v
+-----+-----+
| Sync All |
+-----+-----+
|
v
+----+----+
| Finish |
+---------+
`
---
π¦ Installation
`bash
npm install -g langcleaner
`
---
π Commands & Usage
$3
Run the entire pipeline in one go:
`bash
langcleaner maintenance ./locales/en.json ./src --fix
`
Options:
* --fix: Required to actually update your files. Without it, the tool only generates reports.
$3
| Command | Purpose | Sample Usage |
| --------------------------- | ------------------------------------ | ------------------------------------------------------------- |
| dedupe | Merges duplicate values in JSON | langcleaner dedupe ./locales/en.json --fix |
| apply-code-updates | Updates code based on dedupe mapping | langcleaner apply-code-updates ./output/update-mapping.json ./src |
| find-unused-keys | Removes dead keys from JSON | langcleaner find-unused-keys ./locales/en.json ./src --fix |
| find-missing-translations | Stubs out missing keys in JSON | langcleaner find-missing-translations ./locales/en.json ./src --fix |
| sync-lang | Syncs a language to match master | langcleaner sync-lang ./locales/en.json ./locales/de.json |
| sync-all | Syncs all languages to match master | langcleaner sync-all ./locales/en.json ./locales |
---
π Understanding the
output/ folder
LangCleaner follows a Safety-First approach. It never overwrites your primary master file. Instead, it creates an output/ directory:
`plaintext
output/
βββ en/
βββ cleaned-en.json <-- Your "Gold Standard" file
βββ update-mapping.json <-- Logic used to update code
βββ unused-keys-report.json <-- Audit of what was deleted
βββ missing-keys-report.json <-- Audit of what needs translation
`
$3
Before dedupe:
`json
{
"save": "Submit",
"apply": "Submit",
"cancel": "Cancel"
}
`
After dedupe:
`json
{
"save": "Submit",
"cancel": "Cancel"
}
`
$3
Every report is standardized for your team's review:
* Config: Shows absolute paths and files scanned.
* Summary: High-level stats (e.g., "37% of keys were unused").
* Details: Alphabetical lists of exactly which keys were changed.
---
π‘ Pro-Tips
* Always use a Master: Choose one language (usually English) as your master path.
* Dry Run: Run commands without --fix first to see the JSON reports and verify changes.
* Commit First: Always commit your code to Git before running with --fix` so you can easily revert if needed.