Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 1.91 KB

File metadata and controls

45 lines (35 loc) · 1.91 KB

@skyra/i18next-type-generator

A fast and modern type augmentation generator for the @skyra/i18next-backend filesystem-based i18next backend for Node.js.

Usage

$ 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
#   --no-prettier              Disable prettier
#   -h, --help                 display help for command

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

// This file is automatically generated, do not edit it.
import 'i18next';

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

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.

This utility does not provide formatting options, so prettier is used under the hood to format it before writing to a file, you may opt-out using --no-prettier if you want to use a different tool.

Note: If you want to customize i18next's CustomTypeOptions to add extra options, create a different file, TypeScript will merge the two of them.