Registry / devops / i18next-scanner-typescript

i18next-scanner-typescript

JSON →
library1.2.1jsnpmunverified

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-typescript
INSTALL
IMPORT
SIG · I18NEXT-SCANNER-TY
I
i18next-scanner-typescript
devopsjavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

typescriptTransform
const typescriptTransform = require('i18next-scanner-typescript');
import typescriptTransform from 'i18next-scanner-typescript';
The transform is designed to be consumed in CommonJS configuration files for i18next-scanner. Direct ESM imports are not typically supported for config files.

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.

const typescriptTransform = require('i18next-scanner-typescript'); const path = require('path'); module.exports = { input: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.spec.{js,jsx,ts,tsx}'], output: path.join(__dirname, 'public/locales/{{lng}}/translation.json'), options: { debug: true, sort: true, lngs: ['en', 'fr'], defaultValue: (lng, namespace, key) => key, resource: { loadPath: path.join(__dirname, 'public/locales/{{lng}}/{{ns}}.json'), savePath: path.join(__dirname, 'public/locales/{{lng}}/{{ns}}.json'), jsonIndent: 2, }, func: { extensions: ['.js', '.jsx'], // Important: Only list JS/JSX extensions here list: ['i18next.t', 't'], }, trans: { extensions: ['.js', '.jsx'], // Important: Only list JS/JSX extensions here component: 'Trans', }, }, transform: typescriptTransform( { extensions: ['.ts', '.tsx'], // List TS/TSX extensions for the transform itself tsOptions: { target: 'es2017', jsx: 'react', }, }, function customTransform(outputText, file, enc, done) { // `this` context here is the i18next-scanner parser instance // Access parsing functions via `this.parseFuncFromString`, etc. this.parser.parseTransFromString(outputText); this.parser.parseFuncFromString(outputText); done(); } ), };
Debug
Known issues
gotchaDo NOT include `.ts` or `.tsx` file extensions in the `options.func.extensions` or `options.trans.extensions` arrays in your `i18next-scanner` configuration. These options are for `i18next-scanner` to process already-JavaScript files. The `typescriptTransform` handles transpilation of TS/TSX independently.
fix
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.
affects: >=1.0.0
breakingThe `i18next-scanner-typescript` package specifies a peer dependency on `typescript` version `5.x`. Using an incompatible version of TypeScript (e.g., 4.x or 6.x) may lead to transpilation errors or unexpected behavior.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , i18next_scanner_typescript_1.default) is not a function
Attempting to import `i18next-scanner-typescript` using an ES module `import` syntax in a CommonJS context (e.g., a `.js` config file). The package exports a CommonJS module with a default function.
fix
Use CommonJS `require` syntax: `const typescriptTransform = require('i18next-scanner-typescript');`
SyntaxError: 'import' and 'export' may only appear with 'sourceType: module'
i18next-scanner is attempting to parse a TypeScript file directly because the `typescriptTransform` is either not configured correctly or the `.ts`/`.tsx` extensions are mistakenly included in the main `options.func.extensions` or `options.trans.extensions`.
fix
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`.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
typescriptrequiredRequired for TypeScript transpilation within the transform. Must be version 5.x.
Agent activity
4 hits · last 30 days
node
4
Resources
i18next-scanner-typescript — npm install i18next-scanner-typescript · libregistry