A lightweight pre-commit hook to check for missing translations in TypeScript projects
Automatically scan your staged files for translation keys (t()
function) and update the translation files if necessary. This tool is designed to help developers keep their localization files up-to-date during the commit process.
- Automatically detects
t()
calls in TSX/TS/JS/JSX files - Compares the detected keys with your localization JSON files (e.g.,
fr.json
,he.json
) - Adds missing keys with empty strings and alerts the developer
- Simple configuration via the
.pre-commit-config.yaml
file - Customizable via command-line arguments
-
Install Pre-commit Make sure you have
pre-commit
installed on your machine:pip install pre-commit
-
Add the Hook to Your Project
In your project's root directory, create (or update) the
.pre-commit-config.yaml
file and add the following entry:- repo: https://github.com/gamcoh/translations-checker rev: v0.1.8 # Use the latest release hooks: - id: translation-checker args: ["--json-file", "localization/fr.json"]
-
Install the Hook
Run the following command to install the pre-commit hook:
pre-commit install
-
Commit as Usual
Every time you stage and commit TypeScript files (for example), the hook will run and ensure that all translation keys are properly checked and updated in the specified localization JSON file.
By default, the hook scans all staged .ts,.tsx,.js,.jsx
files for calls to the t()
function and compares the keys found with the entries in your localization file (e.g., fr.json
).
You can customize the behavior of the hook using command-line arguments specified in .pre-commit-config.yaml
:
--json-file
: Path to the JSON file where translation keys are stored.
Example:
- repo: https://github.com/gamcoh/translations-checker
rev: v0.1.8
hooks:
- id: translation-checker
args: ["--json-file", "path/to/fr.json"]
translation-checker-precommit/
├── src/ # Rust source code
├── target/ # Compiled binaries
├── examples/ # Example TSX file and fr.json
├── run_translations_checker.sh # Shell script to invoke the Rust binary
├── .pre-commit-hooks.yaml # Pre-commit hook configuration
└── README.md # Project documentation
-
Clone the repository:
git clone https://github.com/gamcoh/translations-checker.git
-
Build the Rust project:
cargo build --release
-
Run the binary directly to test it locally:
./target/release/translation_checker --json-file examples/fr.json examples/main.tsx
Contributions are welcome! Feel free to open an issue or submit a pull request.
- Fork the repository
- Create a new branch (
git checkout -b feature/new-feature
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/new-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to reach out via GitHub Issues or submit any questions. We appreciate feedback and contributions from the community.
If you find this tool helpful, please give it a ⭐️ on GitHub and share it with others in your community!
Happy Coding! 💻