<div align="center">
  <picture>
    <img src="https://cdn.wolfstar.rocks/assets/stars-components/wordmark.webp" alt="Stars Components" width="440" />
  </picture>

# @wolfstar/i18next-type-generator

**Generate the i18next TypeScript augmentation straight from your locale files.**

[![version](https://npmx.dev/api/registry/badge/version/@wolfstar/i18next-type-generator)](https://npmx.dev/package/@wolfstar/i18next-type-generator)
[![downloads](https://npmx.dev/api/registry/badge/downloads/@wolfstar/i18next-type-generator)](https://npmx.dev/package/@wolfstar/i18next-type-generator)
[![license](https://img.shields.io/github/license/wolfstar-project/stars-components?style=flat-square&color=informational)](https://github.com/wolfstar-project/stars-components/blob/main/LICENSE)

</div>

## Description

A fast and modern type augmentation generator for the [`@wolfstar/i18next-backend`](https://www.npmjs.com/package/@wolfstar/i18next-backend) filesystem-based [`i18next`](https://www.npmjs.com/package/i18next) backend for Node.js.

## Usage

```bash
$ i18next-type-generator [options] [source] [destination]

# Arguments:
#   source                     The directory to generate types from (default: "./src/locales/en-US/")
#   destination                The directory to generate types to (default: "./src/@types/i18next.d.ts")
#
# Options:
#   -V, --version              output the version number
#   -v, --verbose              Verbose output
#   -i, --indentation <value>  Indentation for generated output (number of spaces or "tabs", default: tabs)
#   --no-prettier              Disable prettier
#   -h, --help                 display help for command
```

This CLI tool generates a `.d.ts` file with the following structure:

```typescript
// This file is automatically generated, do not edit it.
/* eslint-disable */
/* oxlint-disable */
// oxfmt-ignore
// prettier-ignore
import 'i18next';

// oxfmt-ignore
// prettier-ignore
declare module 'i18next' {
	interface CustomTypeOptions {
		resources: {
			'commands/choice': {
				name: 'choice';
				description: 'Get a random value from a set of choices';
				// ...
			};
			// ...
		} & CustomResources;
	}

	interface CustomResources {}
}
```

The generated `resources` type is intersected with an empty, mergeable `CustomResources` interface. This is the supported extension point: it lets you add resource keys that are not present in your locale JSON (for example keys whose runtime translation is supplied by the consuming application) without redeclaring `CustomTypeOptions.resources`, which would otherwise trigger `TS2717` for consumers that build with `skipLibCheck: false`.

The output includes `eslint-disable` / `oxlint-disable` comments to suppress linting, and `oxfmt-ignore` / `prettier-ignore` comments before each top-level statement to prevent formatters from rewriting the generated file. These ignore directives are always emitted; the `--no-oxfmt` and `--no-prettier` flags only affect the internal formatting pass used to produce the resource block, not the emitted ignore comments.

The command reads the JSON files inside a directory writes their contents into the `.d.ts` file. This is needed because `typeof import(pathToJSON)` requires the JSON files to be included in `tsconfig.json`, which may be undesirable, and because it types the keys and their inferred types, but does not load the exact values, which breaks i18next's ability to extract arguments from strings.

You can control indentation with `-i` / `--indentation` (a space count or `tabs`). `prettier` is also used under the hood to format output before writing to a file; opt out with `--no-prettier` if you want to use a different tool.

> **Note**: To add resource keys that are not generated from your locale JSON, merge them into `CustomResources` from a separate declaration file:
>
> ```typescript
> import 'i18next';
>
> declare module 'i18next' {
> 	interface CustomResources {
> 		'commands/shared': {
> 			extraKey: string;
> 		};
> 	}
> }
> ```
>
> To add other [`CustomTypeOptions` options](https://www.i18next.com/overview/typescript) (such as `defaultNS`), create a separate file too; TypeScript merges the augmentations.
