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

hk-i18n

v1.0.10

Published

自动国际化

Readme

hk-i18n

自动国际化

前提

  • 项目中必须使用i18next来实现国际化
  • node版本>=14.19.0

下载

# npm
npm i hk-i18n
# yarn
yarn add hk-i18n

查看使用帮助

npx hk-i18n

初始化

npx hk-i18n init

会在项目根目录下生成i18n.config,默认配置如下

{
  "matchOpts": [
    "src/**/*.{js,ts,tsx,jsx}",
    { "ignore": ["**/node_modules/**"] }
  ],
  "localesDir": "./locales",
  "cnJsonFileName": "zh-CN.json",
  "translateLan": ["zh-TW"],
  "excelDir": "./excel"
}
  • matchOpts

    匹配文件的选项,参考glob

  • localesDir(string) 要保存的多语言映射文件路径

  • cnJsonFileName(string) 要保存的中文JSON文件名称

  • translateLan(Array<string>) 要将中文翻译成哪几种语言,参考languages

  • excelDir(string) 生成excel的目录

收集中文

  • 匹配文件中的中文并生成中文JSON
npx hk-i18n collect
  • 如果收集过后在项目代码中添加没有新的中文时,默认不会去重新生成JSON文件,如果想重新生成,可以在执行collect时使用强制更新

⚠️注意:谨慎使用该参数,因为生成的JSON的key是自增的数字,如果代码中中文已经被替换为i18next.t('key')的模式,使用强制更新可能使新生成的JSON文件的key和原来的key不一样

  • 如果不想对某一段文字翻译,可以添加魔法注释/*i18n-disable*/中文,在收集中文时会忽略这个中文

翻译中文并生成对应的语言文件

npx hk-i18n translate

默认会将中文JSON中的文案全部翻译,也可以指定只翻译哪些中文,参数是keys1, keys2, ...,多个key以逗号分隔

替换中文

  • 替换代码中的中文,替换后格式为i18next.t('key' /*key代表的中文*/)
npx hk-i18n replace

通过多语言文件生成excel文件

hk-i18n buildExcel
  • 生成的excle默认名称为lan.xlsx
  • 生成的excle默认sheet名称为lan

存在的问题和不足

  • 目前判断是否去替换中文时,使用正则对文本code判断,如果匹配到的文件中有打包压缩后的代码,可能会卡死,记得排除这类文件
  • 使用谷歌免费翻译接口,每天翻译超过一定次数当天调用接口会不成功,需要第二天调用