i18next-scanner-typescript provides essential TypeScript support for the i18next-scanner tool, enabling it to extract internationalization keys from `.ts` and `.tsx` source files. As of its current stable version `1.2.1`, this package acts as a transform layer, transpiling TypeScript code into JavaScript internally before `i18next-scanner` processes it. This ensures that the scanner can correctly identify `t()` calls and `<Trans>` components in modern TypeScript applications without requiring a separate pre-build step. It is an active part of the `i18next` ecosystem, maintained to ensure compatibility with both `i18next-scanner` and contemporary TypeScript versions, currently requiring `typescript@5.x` as a peer dependency. Its primary differentiator is simplifying the integration of i18n scanning into TypeScript-based projects by handling the necessary transpilation transparently.
npm install i18next-scanner-typescriptVerified import paths — ran on the pinned version, not inferred.
This configuration sets up `i18next-scanner` to process TypeScript and TSX files using the `i18next-scanner-typescript` transform. It demonstrates how to specify the TS/TSX file extensions for the transform while correctly excluding them from the scanner's primary `func` and `trans` options. The custom transform function provides access to `i18next-scanner`'s internal parser to process the transpiled output. To run this, first install `i18next-scanner`, `i18next-scanner-typescript`, and `typescript` as dev dependencies. Create an example `src/App.tsx` file with i18n keys (e.g., `<Trans>Hello</Trans>` or `t('key')`). Then, execute `npx i18next-scanner --config i18next-scanner.config.js` to extract keys.
Ensure `options.func.extensions` and `options.trans.extensions` only contain `.js`, `.jsx`, or similar JavaScript extensions. Configure the TS/TSX extensions solely within the `typescriptTransform` options.
Ensure your project's `typescript` dependency is set to `5.x`. You may need to run `npm install typescript@5` or `yarn add typescript@5` if there's a conflict.
Use CommonJS `require` syntax: `const typescriptTransform = require('i18next-scanner-typescript');`Verify that `typescriptTransform` is correctly added to the `transform` array in your `i18next-scanner` configuration, and crucially, ensure that `.ts` and `.tsx` are NOT listed in the `options.func.extensions` or `options.trans.extensions`.