Skip to content

Justinidlerz/i18n-scanner-rs

Repository files navigation

I18n scanner rs

CI

A superfast i18next scanner tool written in Rust, based on Oxc
The node.js API is implemented by NAPI

How it works

This will follow the below flows to collect all the I18n contents via passed entry file

  1. Analyze all file references from entry files
  2. Find all import statements are includes the list below:
    • import * from 'i18next'
    • import * from 'react-i18next'
    • or any you passed packages
  3. find out the variable linked to the import statement
  4. recursively analyze the variable's references
  5. collect the first parameter of i18n function call or bypass from another function wrapped by the i18n function

Usage

import { scan } from '@i18n-scanner-rs/main'

const payload = {
  tsconfigPath: './tsconfig.json',
  entryPaths: ['./src/index.ts'],
  externals: ['react-i18next'],
  extendI18NPackages: []
}

const result = scan(payload)

console.log(result)

Type declarations

export interface Member {
    name: string
    type: I18nType
    ns?: string
}
export interface I18NPackage {
    packagePath: string
    members: Array<Member>
}

export const enum I18nType {
    Hook = 'Hook',
    TMethod = 'TMethod',
    TransComp = 'TransComp',
    TranslationComp = 'TranslationComp',
    HocWrapper = 'HocWrapper',
    ObjectMemberT = 'ObjectMemberT'
}
export interface Payload {
    tsconfigPath: string
    entryPaths: Array<string>
    externals: Array<string>
    extendI18NPackages?: Array<I18NPackage>
}

export declare function scan(payload: Payload): Record<string, Array<string>>

License

For a detailed explanation on how things work, checkout the Oxc and NAPI doc

Copyright (c) 2025-present, Idler.zhu

About

An superfast i18next scanner tool written in Rust, based on Oxc

Resources

License

Stars

Watchers

Forks

Packages

No packages published