How mololab/json-translator works
Project type and purpose
• This is a Node.js‐based CLI tool *and* a reusable package (“@parvineyvazov/json-translator”) whose job is to take JSON/YAML files or in-memory JSON objects, break them down, translate all text values via one of several external translation services or AI models, reassemble the output, and write it back to disk or return it to the caller.
File structure
• Top level:
• bin/jsontt → the shipped CLI executable
• docs/ → language support reference
• src/
– cli/ → parses arguments, prompts, drives the flow
– core/ → engine plumbing: reading/writing files, placeholder handling, orchestration
– modules/ → implements each translation strategy (Google, Bing, DeepL, OpenAI, etc.)
– utils/ → YAML parser, console I/O helpers, micro concurrency queue
– index.ts → package entrypoint exporting the public API
• Config/build files: rollup.config.js, tsconfig.json, jest.config.js, makefile
Extract key insights from the README
• Two “faces” of the system: the CLI (jsontt <path> [options]) and the programmatic API (translateWord, translateObject, translateFile, etc.).
• Supports multiple translation backends via a plug-in (“strategy”) model.
• Handles deep JSON structures, placeholder ignoring, proxy lists, concurrency limits, fallback logic.
Main components & their interactions
a. Components:
1. CLI Frontend
2. Argument Parser & Prompt (src/cli)
3. Core Orchestrator (src/core/translator.ts & core.ts)
4. File I/O layer (src/core/json_file.ts, proxy_file.ts)
5. JSON Processor (src/core/json_object.ts)
6. Placeholder Ignorer (src/core/ignorer.ts)
7. Translation Module Manager (src/modules/modules.ts + modules/functions.ts + modules/languages.ts)
8. Individual Module Implementations (Google/Bing/Libre/Argos/DeepL/OpenAI…)
9. Utility Layer (YAML parser, concurrency “micro” queue, console logger)
10. External Services (HTTP APIs, OpenAI endpoints)
11. Disk / Environment (filesystem, env-vars for API keys)
• User invokes jsontt → CLI Frontend
• CLI → Argument Parser → Core Orchestrator
• Orchestrator → File I/O reads JSON/YAML
• JSON Processor flattens/traverses object
• Placeholder Ignorer extracts tokens (e.g. {name}, URLs)
• Orchestrator → Module Manager selects translation strategy
• Strategy → External Service → returns translated strings
• Orchestrator merges results → Placeholder Ignorer re-inserts tokens
• Orchestrator → File I/O writes output file(s)
• CLI → Console Logger reports progress/status
c. Architectural patterns:
• Strategy pattern for pluggable translation modules
• Pipeline design (read → preprocess → translate → postprocess → write)
• Separation of concerns: CLI vs. Core vs. Modules vs. Utils
• Concurrency control via “micro” queue and optional proxy support
d. Key technologies/frameworks:
• Node.js + TypeScript
• Rollup for bundling the package
• Jest for unit tests
• External HTTP clients (fetch or axios inside modules)
• Env-vars for API keys (OPENAI_API_KEY, DEEPL_API_KEY, etc.)