enable-generate-locales
v1.0.3
Published
Scans packages for '###' localization tokens and generates/updates _locale.json files.
Downloads
497
Readme
enable-generate-locales
Scans a monorepo for ###-prefixed localization tokens embedded in source
files and generates or updates a _locale.json file in the respective package
root for each one found.
Example token in code:
'###features.dashboard.toolbar.addNew|Add New'Generated output in <packageRoot>/src/_locale.json if a src/ folder exists, otherwise <packageRoot>/_locale.json (nested via dot-notation):
{
"en-us": {
"features": {
"dashboard": {
"toolbar": {
"addNew": "Add New"
}
}
}
}
}Usage
npx enable-generate-locales [options] [directories...]Run from the root of your monorepo (or pass target directories as positional arguments). Progress and results are printed to stdout.
Options
| Flag | Description |
|------|-------------|
| -l, --locale <locale> | Locale code to populate in _locale.json (default: en-us) |
| -e, --ext <extensions> | Comma-separated list of file extensions to scan (default: js,jsx,ts,tsx,html,vue,json,mjs,cjs) |
| -p, --allowedPackages <patterns> | Comma-separated list of package name patterns to scan inside node_modules (e.g. @my-org/*,shared-*) |
| --flat | Output flat keys instead of nested dot-notation objects |
| -c, --clean | Clean/overwrite existing _locale.json instead of merging |
| -d, --dry-run | Scan and report without writing any files |
| -a, --aggregate <path> | Aggregate all discovered keys into a single target package or file |
| -v, --verbose | Print detailed extraction info per file |
| -h, --help | Show usage help |
Ignored by default
- Directories:
node_modules(except packages matching--allowedPackages),.git,.nx,dist,build,.release,.next,.cache,.venv,coverage,.turbo,__tests__,__mocks__,stories,story - Test files (
*.test.*,*.spec.*) and Storybook files (*.stories.*,*.story.*) - Specific files:
package.json,package-lock.json,pnpm-lock.yaml,pnpm-workspace.yaml,_locale.json,_permissions.json,tsconfig.json,jsconfig.json,nx.json,babel.config.json,eslintrc.json,prettierrc.json
Examples
# Scan the whole workspace
npx enable-generate-locales
# Scan a specific directory
npx enable-generate-locales src/features/dashboard
# Preview changes without writing files
npx enable-generate-locales --locale en-us --dry-run
# Aggregate tokens from allowed node_modules packages into one target
npx enable-generate-locales --aggregate apps/web-app --allowedPackages "@my-scope/*,shared-ui-*"