-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add i18next-type-generator #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RedStar071
wants to merge
6
commits into
main
Choose a base branch
from
feat/add-i18next-type-generator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a59e63d
feat: add i18next-type-generator and migrate i18n to i18next v25
RedStar071 1990dee
fix(i18next-type-generator): wire --indentation flag through generate
cursoragent 2ae20d3
feat(i18next-type-generator): enhance CLI and output generation
RedStar071 3c43053
chore(i18next-type-generator): clean up CHANGELOG and enhance README
RedStar071 67d9424
fix(i18next-type-generator): change default indentation from tab to '…
RedStar071 f5da3a7
test(i18next-type-generator): add comprehensive tests for CLI and gen…
RedStar071 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,3 @@ | ||
| export { default as i18next, type InitOptions, type TFunction, type TOptions, type TOptionsBase } from 'i18next'; | ||
| export * from './lib/functions.js'; | ||
| export * from './lib/registry.js'; | ||
| export type * from './lib/types.js'; | ||
| export * from './lib/utils.js'; | ||
|
|
||
| import type { NonNullObject } from '@sapphire/utilities'; | ||
| import type { TypedFT, TypedT } from './lib/types.js'; | ||
|
|
||
| declare module 'i18next' { | ||
| export interface TFunction { | ||
| lng: string; | ||
| ns?: string; | ||
|
|
||
| <TReturn>(key: TypedT<TReturn>, options?: TOptionsBase | string): TReturn; | ||
| <TReturn>(key: TypedT<TReturn>, defaultValue: TReturn, options?: TOptionsBase | string): TReturn; | ||
| <TArgs extends NonNullObject, TReturn>(key: TypedFT<TArgs, TReturn>, options?: TOptions<TArgs>): TReturn; | ||
| <TArgs extends NonNullObject, TReturn>(key: TypedFT<TArgs, TReturn>, defaultValue: TReturn, options?: TOptions<TArgs>): TReturn; | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # @wolfstar/i18next-type-generator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # `@wolfstar/i18next-type-generator` | ||
|
|
||
| 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'; | ||
| // ... | ||
| }; | ||
| // ... | ||
| }; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 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**: If you want to customize `i18next`'s `CustomTypeOptions` to add [extra options](https://www.i18next.com/overview/typescript), create a different file, TypeScript will merge the two of them. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| { | ||
| "name": "@wolfstar/i18next-type-generator", | ||
| "version": "3.0.1", | ||
| "description": "A fast utility that generates the TypeScript augmentation for i18next.", | ||
| "keywords": [ | ||
| "api", | ||
| "discord", | ||
| "http", | ||
| "i18next", | ||
| "pnpm", | ||
| "ts", | ||
| "typescript", | ||
| "wolfstar" | ||
| ], | ||
| "homepage": "https://github.com/wolfstar-project/stars-components/tree/main/packages/i18next-type-generator", | ||
| "bugs": { | ||
| "url": "https://github.com/wolfstar-project/stars-components/issues" | ||
| }, | ||
| "license": "Apache-2.0", | ||
| "author": "@wolfstar", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/wolfstar-project/stars-components.git", | ||
| "directory": "packages/i18next-type-generator" | ||
| }, | ||
|
RedStar071 marked this conversation as resolved.
|
||
| "bin": { | ||
| "i18next-type-generator": "./dist/cli.js" | ||
| }, | ||
| "files": [ | ||
| "dist/" | ||
| ], | ||
| "type": "module", | ||
| "sideEffects": false, | ||
| "main": "dist/cli.js", | ||
| "exports": { | ||
| ".": { | ||
| "default": "./dist/cli.js" | ||
| } | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "scripts": { | ||
| "test": "vitest run", | ||
| "build": "tsdown --config-loader unrun", | ||
| "watch": "tsdown --config-loader unrun --watch", | ||
| "typecheck": "tsc -p ../../tsconfig.json", | ||
| "lint": "oxlint src --fix", | ||
| "prepack": "pnpm run build" | ||
| }, | ||
| "dependencies": { | ||
| "citty": "^0.1.6", | ||
| "colorette": "^2.0.20", | ||
| "tslib": "^2.8.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "22.15.21", | ||
| "@vitest/coverage-v8": "^4.1.8", | ||
| "i18next": "^25.10.10", | ||
| "tsdown": "^0.22.2", | ||
| "typescript": "~5.8.3", | ||
| "vitest": "^4.1.8" | ||
| }, | ||
| "optionalDependencies": { | ||
| "oxfmt": "^0.53.0", | ||
| "prettier": "^3.5.3" | ||
| }, | ||
| "engines": { | ||
| "node": ">=20" | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.