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 🙏

© 2025 – Pkg Stats / Ryan Hefner

hecom-i18n-tools

v1.4.0

Published

RN/JS/TS 多项目国际化扫描与Excel导出/导入工具

Readme

HECOM I18N Tools

🌍 专为 React Native/React/TypeScript 项目设计的国际化工具

npm version License: MIT

✨ 特性

  • 🔍 自动扫描: 智能识别代码中的中文文本
  • 🚫 智能忽略: 自动忽略 testID、注释等无需翻译的内容
  • 🔄 一键替换: 自动将中文替换为 t() 函数调用
  • 📊 Excel管理: 使用 Excel 管理翻译,方便团队协作
  • 🔗 GitLab集成: 自动生成源码链接,快速定位
  • 📈 增量更新: 支持版本迭代的增量翻译管理

🚀 快速开始

安装

npm install hecom-i18n-tools -D

使用 npx(无需安装)

# 直接使用 npx 运行,无需全局安装
npx hecom-i18n-tools scan -s 'src' -o 'i18n-result.xlsx'
npx hecom-i18n-tools replace --excel=i18n-result.xlsx --importPath='@/utils/i18n'
npx hecom-i18n-tools gen

基础用法

# 1. 扫描中文文本并生成 Excel
hecom-i18n-tools scan -s 'src' -o 'i18n-result.xlsx'

# 2. 替换代码中的中文为 t() 调用
hecom-i18n-tools replace --excel=i18n-result.xlsx --importPath='@/utils/i18n'

# 3. 生成语言包文件
hecom-i18n-tools gen

📋 完整示例

转换前

function App() {
  return (
    <View>
      <Text>欢迎使用我们的应用</Text>
      <Button title="确认提交" onPress={handleSubmit} />
      <Text testID="测试标识">用户名</Text>  // testID 自动忽略
    </View>
  );
}

转换后

import { t } from '@/utils/i18n';

function App() {
  return (
    <View>
      <Text>{t("i18n_abc123def")}</Text>
      <Button title={t("i18n_def456ghi")} onPress={handleSubmit} />
      <Text testID="测试标识">{t("i18n_ghi789jkl")}</Text>
    </View>
  );
}

生成的翻译文件

| key | zh | en | file | line | |-----|----|----|------|------| | i18n_abc123def | 欢迎使用我们的应用 | Welcome to our app | src/App.tsx | 4 | | i18n_def456ghi | 确认提交 | Confirm | src/App.tsx | 5 | | i18n_ghi789jkl | 用户名 | Username | src/App.tsx | 6 |

📖 详细文档

🔧 命令详解

scan - 扫描文本

hecom-i18n-tools scan [options]

选项:
  -s, --src <paths>         源码目录,支持多个路径
  -o, --out <file>          输出 Excel 文件路径  
  --gitlab <url>            GitLab 项目地址
  --config <file>           配置文件路径

replace - 替换文本

hecom-i18n-tools replace [options]

选项:
  --excel <file>           Excel 翻译文件路径
  --file <file>            只处理指定文件
  --importPath <path>      i18n 导入路径
  --fixLint               自动修复 ESLint

gen - 生成语言包

hecom-i18n-tools gen [options]

选项:
  --excel <file>           Excel 文件路径
  --output <dir>           语言包输出目录

📞 技术支持

  • 🐛 问题反馈: GitHub Issues
  • 📖 详细文档: 查看项目内的 Markdown 文档
  • 💬 技术讨论: 联系项目维护团队

📄 许可证

MIT © HECOM


让国际化变得简单高效! 🌍

Excel说明

  • key: 唯一key
  • zh: 中文
  • file: 文件路径
  • line: 行号
  • gitlab: 跳转链接
  • en/ja...: 各语言

命令行参数

scan 命令

| 参数 | 必需 | 描述 | |------|------|------| | -s, --dist | 是 | 源代码目录(支持多个,用逗号分隔) | | -o, --out | 是 | 输出Excel路径 | | -g, --gitlab | 否 | GitLab仓库URL前缀 | | -c, --config | 否 | 配置文件路径 |

replace 命令

| 参数 | 必需 | 描述 | |------|------|------| | -e, --excel | 是 | Excel文件路径 | | -i, --importPath | 是 | import路径 | | -f, --file | 否 | 仅处理指定文件 | | -l, --fixLint | 否 | 是否修复lint |

gen 命令

| 参数 | 必需 | 描述 | |------|------|------| | -e, --excel | 是 | Excel文件路径 | | -o, --out | 是 | 输出目录 |

✅ 生成语言包冲突检测测试

项目内置最小测试脚本验证以下行为:

  1. 无冲突:正常生成多语言 json。
  2. 冲突(已有 json 中同 key 不同翻译):应阻止生成,不覆盖旧文件,并生成 conflicts-*.json 报告,Excel 原文件不删除。

运行测试:

yarn test

测试脚本位置:test/run-tests.js (使用 Node 原生 assert,无需额外依赖)。

🛠 可配置日志忽略

扫描时默认会忽略以下日志对象/方法中的中文:

  • 对象:console, UnionLog
  • 方法:log, warn, error, info, debug, trace, verbose, fatal

现在可通过配置文件追加自定义日志(例如忽略 Sentry.captureMessage 中的中文):

提示:配置项是“追加”而不是“覆盖”,仍会保留默认忽略的 console/UnionLog 及其方法。