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

vue-i18n-extract-esm

v1.0.25

Published

ESModule CLI to auto extract Chinese to vue-i18n JSON

Readme

vue-i18n-extract-esm

TypeScript ESModule 一键提取 & 替换 Vue / React / 任意项目中的硬编码中文,自动生成语义化 key,零 AST 语法报错。

  1. 安装 bash 复制 npm i -D vue-i18n-extract-esm

or

pnpm add -D vue-i18n-extract-esm 2. 最快上手(默认配置) bash 复制

仅提取中文到 src/lang/zh-CN.json

npx i18n-extract

提取 + 自动把源码中文替换成 $t('xxx')

npx i18n-extract --replace 3. 自定义配置(项目级) 在项目根目录新建 i18n.config.js(或 .json)即可完全覆盖默认行为:

// i18n.config.js
module.exports = {
  src: 'src',
  out: 'src/lang/zh-CN.json',
  ext: ['vue', 'ts'],
  translate: {
    enable: true,           // 是否自动翻译英文
    target: 'en',           // 目标语言
    driver: 'translate',    // 离线包,也可换 'google' / 'baidu'
    enOut: 'src/lang/en-US.json' // 英文文件路径
  },
  replace: { enable: true, fn: '$t', ext: ['vue', 'ts'] }
};```

表格
复制
字段	说明	默认值
src	源码根目录	src
out	中文语言文件路径	src/lang/zh-CN.json
ext	扫描后缀列表	['vue','js','jsx','ts','tsx']
replace.enable	是否自动替换源码	false
replace.fn	国际化函数名	$t
replace.ext	需替换的文件后缀	同 ext
支持 向上递归查找配置;子目录运行也能命中项目根配置。
4. 多项目示例
表格
复制
技术栈	配置模板
Vite + Vue3 + TS	ext:['vue','ts'], fn:'t'
Nuxt3	src:'.', ext:['vue','ts'], fn:'$t'
React + TSX	ext:['tsx','ts'], fn:'i18n.t'
仅提取不替换	replace:{enable:false}
5. 生成 key 规则
中文 → 小写拼音 + 下划线,可读性高:
JSON
复制
{
  "ji_qun_xia_la": "集群下拉",
  "qing_shu_ru_yong_hu_ming": "请输入用户名"
}
6. 目录结构
复制
your-project/
├─ i18n.config.js      # 项目配置(可选)
├─ src/
│  ├─ lang/
│  │  └─ zh-CN.json    # 自动生成
│  └─ App.vue
└─ package.json
7. 常见命令
bash
复制
# 查看当前生效配置
npx i18n-extract --help

# 临时覆盖配置
npx i18n-extract --src apps --out apps/lang/zh-CN.json --replace
8. 注意事项
首次运行前请 commit 代码,方便 diff。
替换后请 eslint --fix 自动格式化。
.vue 文件仅替换 <script> 内容,模板中文已用正则提取,不破坏标签结构。
9. 卸载
bash
复制
npm r -D vue-i18n-extract-esm
「复制配置 → 跑命令 → 中文全部进 JSON」,搞定!