README.md

July 29, 2026 · View on GitHub

ngx-i18n-extract-regex-cli logo

ngx-i18n-extract-regex-cli

Extract Transloco and ngx-translate keys from Angular templates and TypeScript files.

npm version Build & Publish license

Installation

Node.js 22.12 or newer is required to run the published CLI.

Install the CLI globally:

npm install --global ngx-i18n-extract-regex-cli

You can also run it without a global installation:

npx ngx-i18n-extract-regex-cli --help

Usage

From the root of an Angular project, run:

ngx-i18n-extract-regex-cli extract --library transloco

By default, the CLI:

  • scans src/app/**/*.ts and src/app/**/*.html;
  • reads language files matching src/assets/i18n/*.json;
  • retains values for translation keys that already exist;
  • adds missing values as ███; and
  • removes unused keys and writes the remaining keys in alphabetical order.

Use --dry-run to inspect the number of discovered keys without changing language files:

ngx-i18n-extract-regex-cli extract --library ngx-translate --dry-run

Custom paths

Paths are resolved relative to --cwd. Quote glob patterns so that the CLI, rather than your shell, expands them.

ngx-i18n-extract-regex-cli extract \
  --library transloco \
  --cwd projects/example/src \
  --source 'app/**/*.ts' 'app/**/*.html' \
  --langs 'assets/i18n/*.json' \
  --default-value 'TODO'

Supported expressions

The extractor recognizes common static string usages, including:

{{ 'home.title' | transloco }} {{ 'home.title' | translate }}
transloco.translate('home.title');
translate.instant('home.title');
_('home.title');

Dynamic keys cannot be discovered reliably and should be added to your language files by another mechanism.

Options

OptionValuesDefaultDescription
--librarytransloco, ngx-translatetranslocoSelect the i18n library syntax to scan for.
--cwdpathsrcSet the base directory for source and language globs.
--sourceone or more globsapp/**/*.ts app/**/*.htmlSelect source files to scan.
--langsone or more globsassets/i18n/*.jsonSelect language JSON files to update.
--default-valuestring███Set the value assigned to newly discovered keys.
--dry-runflagdisabledScan without writing language files.
--encodingNode.js buffer encodingutf-8Set the source and output file encoding.

Run ngx-i18n-extract-regex-cli extract --help for the complete command help.

Development

Development uses the Node.js version declared in .nvmrc and the Bun version declared in package.json:

nvm install
nvm use
bun install
bun run lint
bun run build
bun run test:coverage

See CONTRIBUTING.md for contribution guidelines.

License

Copyright © 2024–2026 Dominik Hladík

Licensed under the MIT License.