@ofkm/unused-i18n
v0.1.0
Published
Detect and optionally remove unused i18n translations.
Readme
unused-i18n
Detect and optionally remove unused i18n translations by scanning your codebase.
Install
pnpm add -D unused-i18nQuick start
pnpm dlx unused-i18nOptionally remove unused keys:
pnpm dlx unused-i18n --removeRun in interactive mode:
pnpm dlx unused-i18n --interactiveConfig file
Create unused-i18n.config.json at the repo root:
{
"locale": "en",
"messagesDir": "frontend/messages",
"srcDir": "frontend/src",
"ignoreDirs": ["frontend/src/vendor"],
"remove": false,
"allowedExts": [".js", ".ts", ".svelte"],
"excludeKeys": ["_comment", "$schema"],
"matcher": "\\bm(?:\\?\\.|\\.)\\s*([a-zA-Z_][a-zA-Z0-9_]*(?:\\s*(?:\\?\\.|\\.)\\s*[a-zA-Z_][a-zA-Z0-9_]*)*)\\s*(?:\\(|\\?\\.\\s*\\()"
}You can also point to a custom config:
pnpm dlx unused-i18n --config ./configs/unused-i18n.jsonCLI options
--config <path>: Config file path (default:unused-i18n.config.json)--locale <locale>: Locale file name (default:en)--messages-dir <dir>: Directory containing locale JSON files--src-dir <dir>: Source directory to scan--ignore-dir <dir>: Ignore a directory (repeatable)--ignore-dirs <list>: Comma-separated ignore directories--allowed-exts <list>: Comma-separated extensions to scan--exclude-keys <list>: Comma-separated excluded keys--matcher <pattern>: Regex for i18n key access--remove: Remove unused keys-i, --interactive: Prompt for settings interactively
Environment variables
I18N_CONFIG: Config pathI18N_LOCALEI18N_MESSAGES_DIRI18N_SRC_DIRI18N_IGNORE_DIRI18N_REMOVE(trueorfalse)
Library usage
import { mergeConfig, runUnusedI18n } from 'unused-i18n';
const config = mergeConfig({
locale: 'en',
messagesDir: 'frontend/messages',
srcDir: 'frontend/src',
remove: false,
});
const result = runUnusedI18n(config);
console.log(result.unused);Development
pnpm install
pnpm build