npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

i18n-xy

v0.0.30

Published

自动提取React项目中的中文字符串并进行国际化的CLI工具

Readme

i18n-xy

A CLI tool for automatically extracting Chinese strings from React projects and internationalizing them. Supports intelligent string extraction, AST code transformation, key generation, automatic translation, and more.

✨ Features

  • 🚀 Automatic Extraction: Intelligently identifies and extracts Chinese strings from JavaScript/TypeScript/JSX/TSX files
  • 🔄 Code Transformation: Uses AST technology to precisely replace Chinese strings with internationalization function calls
  • 🎯 Smart Key Generation: Supports pinyin conversion, hash generation, duplicate key detection, and other strategies
  • 🌐 Automatic Translation: Integrated with Baidu Translate API for batch translation of internationalization files
  • ⚙️ Flexible Configuration: Rich configuration options to meet different project requirements
  • 📁 File Management: Supports temporary directory processing to avoid directly modifying source files
  • 🔧 Auto Import: Configurable automatic addition of internationalization function import statements
  • 📊 Detailed Logging: Multi-level log output for easy debugging and monitoring

📦 Installation

# Global installation
npm install -g i18n-xy

# Or using pnpm
pnpm add -g i18n-xy

# Or using yarn
yarn global add i18n-xy

🚀 Quick Start

1. Initialize Configuration

# Initialize configuration file
i18n-xy init
# Or use short command
i18nx init

2. Extract Chinese Strings

# Use default configuration to extract
i18n-xy extract

# Specify configuration file
i18n-xy extract -c ./my-config.json

3. Translate Internationalization Files

# Batch translation
i18n-xy translate --batch

# Translate single text
i18n-xy translate --test -f zh -t en -i "你好世界"

⚙️ Basic Configuration

Configuration file example (i18n.config.json):

{
  "locale": "zh-CN",
  "displayLanguage": "en-US",
  "outputDir": "locales",
  "include": [
    "src/**/*.{js,jsx,ts,tsx}",
    "pages/**/*.{js,jsx,ts,tsx}",
    "components/**/*.{js,jsx,ts,tsx}"
  ],
  "exclude": [
    "node_modules/**",
    "dist/**",
    "build/**",
    "**/*.test.{js,jsx,ts,tsx}"
  ],
  "replacement": {
    "functionName": "$t",
    "autoImport": {
      "enabled": true,
      "insertPosition": "afterImports"
    }
  }
}

Core Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | locale | string | "zh-CN" | Source language | | outputDir | string | "locales" | Internationalization file output directory | | include | string[] | ["src/**/*.{js,jsx,ts,tsx}"] | File patterns to process | | exclude | string[] | ["node_modules/**"] | File patterns to exclude | | replacement.functionName | string | "$t" | Replacement function name |

🛠️ Development

Environment Requirements

  • Node.js >= 16.0.0
  • npm/pnpm/yarn

Local Development

# Clone project
git clone <repository-url>
cd i18n-xy

# Install dependencies
pnpm install

# Development mode
pnpm dev

# Build
pnpm build

# Code check
pnpm lint

# Type check
pnpm type-check

Project Structure

src/
├── ast/           # AST processing core logic
├── cli.ts         # CLI command line entry
├── config/        # Configuration management
├── translation/   # Translation functionality
├── utils/         # Utility functions
└── vars/          # Variable management

📚 Usage Examples

Before Processing

function Welcome({ name }) {
  return (
    <div>
      <h1>欢迎使用我们的系统</h1>
      <p>用户:{name},您好!</p>
      <button onClick={handleClick}>点击开始</button>
    </div>
  );
}

After Processing

import { useTranslation } from 'react-i18next';

function Welcome({ name }) {
  const { t: $t } = useTranslation();
  
  return (
    <div>
      <h1>{$t("huan_ying_shi_yong_wo_men_de_xi_tong")}</h1>
      <p>{$t("yong_hu")}:{name},{$t("nin_hao")}!</p>
      <button onClick={handleClick}>{$t("dian_ji_kai_shi")}</button>
    </div>
  );
}

Generated Internationalization File

locales/zh-CN.json:

{
  "huan_ying_shi_yong_wo_men_de_xi_tong": "欢迎使用我们的系统",
  "yong_hu": "用户",
  "nin_hao": "您好",
  "dian_ji_kai_shi": "点击开始"
}

📝 License

ISC

🤝 Contributing

Issues and Pull Requests are welcome!


For more detailed configuration and advanced features, please check the documentation.