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

@dd-code/babel-tools

v0.0.3

Published

Babel plugin to extract and replace Chinese literals with i18n keys

Readme

@dd-code/babel-plugin-i18n

一个用于提取与替换中文文本的 Babel 插件:扫描代码中的中文字符串,生成稳定的 i18n key,并可选择替换为 t('key') 调用,同时将原文写入 locales/<locale>.json

特性

  • 识别中文字符串与(无表达式的)模板字符串
  • 可选模式:仅提取(extract)或替换(replace)
  • 稳定 key 策略:基于内容哈希(sha1 前 8 位)
  • 构建后自动合并写入 locales/zh-CN.json(可配置目录与语言)
  • 忽略导入/导出语句、对象键名、可选忽略 console 与测试文件

安装

pnpm add @dd-code/babel-plugin-i18n -D
# 需要 @babel/core 作为 peer
pnpm add @babel/core -D

使用

.babelrc.js

module.exports = {
  plugins: [
    [
      '@dd-code/babel-plugin-i18n',
      {
        localesDir: './locales',
        locale: 'zh-CN',
        mode: 'replace', // or 'extract'
        functionName: 't',
        includeTemplate: true,
        ignore: { console: true, testFiles: true }
      }
    ]
  ]
};

示例

源代码:

const s = '你好,世界';

替换后:

const s = t('i18n.1a2b3c4d');

同时(在构建结束时)会向 locales/zh-CN.json 写入:

{
  "i18n.1a2b3c4d": "你好,世界"
}

选项

  • localesDir: string,输出目录,默认 ./locales
  • locale: string,目标语言,默认 zh-CN
  • mode: 'extract' | 'replace',默认 replace
  • functionName: string,替换的函数名,默认 t
  • includeTemplate: boolean,是否处理无表达式的模板字符串,默认 false
  • ignore.console: boolean,忽略 console.* 的字符串
  • ignore.testFiles: boolean,忽略 **/*.test.***/*.spec.*

注意

  • 包不会主动安装 @babel/core,需由使用方提供(peerDependencies)
  • 模板字符串包含表达式的情况暂不替换(未来可扩展为带参数插值)

许可

ISC