ng-i18n-cli
v1.1.1
Published
Angular i18n Toolkit CLI
Maintainers
Readme
ng-i18n-cli
A CLI tool for scanning Angular projects and extracting i18n translation keys from HTML and TypeScript files.
Generates a TypeScript translation file with a nested object structure ready to use in your localization pipeline.
🚀 Features
- ✅ Extracts translation keys from Angular HTML and TS files
- ✅ Supports
{{ 'KEY' | translate }}andthis.translate.instant('KEY') - ✅ Generates nested
.tsfiles with structure like:export const english = { Form: { lblSubmit: "" }, Header: { lblTitle: "" } }; - ✅ Custom output filename using
--transflag (e.g.en.ts,hi.ts) - ✅ Smart default paths (
.= current folder) - ⚙️ Designed for real-world Angular i18n workflows
📦 Installation (as dev dependency)
npm install -D ng-i18n-cli🧠 Usage
Basic Command
ng-i18n extractThis will scan the current folder and generate en.ts with all translation keys.
With Custom Language Code
ng-i18n extract --trans hi➡️ This will create hi.ts in the current folder.
Usage (with npx)
npx ng-i18n extract --trans enExample Input
- You want to generate translate file for your dashboard componenet
- Go to that folder in your cmd
- Then run below command
ng-i18n extract --trans en
or
ng-i18n extract -t enSpecify Project Folder
ng-i18n extract --project src/app/dashboardScans only that folder and outputs en.ts inside your root or specified folder.
Full Command Example
ng-i18n extract --project src/app/shared --trans en➡️ Scans src/app/shared
➡️ Generates en.ts with nested key format
🧾 Example Output
Input in HTML:
{{ 'Form.lblSubmit' | translate }}
{{ 'TabelDetails.lblName' | translate }}Input in TypeScript:
this._translate.instant('Form.lblSomeText');
this._translate.instant('ErrorMessage.lblSomeError');Output:
export const english = {
"Form": {
"lblSubmit": "",
"lblSomeText": ""
},
"TabelDetails": {
"lblName": ""
},
"ErrorMessage": {
"lblSomeError": ""
}
};📁 File Structure (Generated)
your-project/
└── i18n/
└── en.ts ✅ Translation file with nested structure🛠 Development Notes
- Built with Node.js + TypeScript
- Build for Angular projects specially
- Uses
globto scan files - File extensions supported:
.html,.ts - Uses regex to extract translation keys
- Future ready for SCAM or grouping modes
Help Section
- If you want to make componenet level custom transalation feature than visit on medium
✨ Author
Made with ❤️ by Ajay R. Khambhayta
