open-index/open-npm huggingface dataset:
npm package: @ofkm/unused-i18n
Description: Detect and optionally remove unused i18n translations.
Latest version: 0.1.0

# unused-i18n

Detect and optionally remove unused i18n translations by scanning your codebase.

## Install

```bash
pnpm add -D unused-i18n
```

## Quick start

```bash
pnpm dlx unused-i18n
```

Optionally remove unused keys:

```bash
pnpm dlx unused-i18n --remove
```

Run in interactive mode:

```bash
pnpm dlx unused-i18n --interactive
```

## Config file

Create `unused-i18n.config.json` at the repo root:

```json
{
	"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:

```bash
pnpm dlx unused-i18n --config ./configs/unused-i18n.json
```

## CLI 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 path
- `I18N_LOCALE`
- `I18N_MESSAGES_DIR`
- `I18N_SRC_DIR`
- `I18N_IGNORE_DIR`
- `I18N_REMOVE` (`true` or `false`)

## Library usage

```ts
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

```bash
pnpm install
pnpm build
```