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 🙏

© 2024 – Pkg Stats / Ryan Hefner

kiwi-cli-base

v1.0.25

Published

a cli for kiwi

Downloads

159

Readme

🐤 kiwi cli

Kiwi 的 CLI 工具

如何使用

yarn global add kiwi-clis

推荐与🐤 Kiwi-国际化全流程解决方案结合使用

CLI 参数

kiwi --init

初始化项目,生成 kiwi 的配置文件 kiwi-config.json

{
  // kiwi文件根目录,用于放置提取的langs文件
  "kiwiDir": "./.kiwi",

  // 配置文件目录,若调整配置文件,此处可手动修改
  "configFile": "./.kiwi/kiwi-config.json",

  // 语言目录名,注意连线和下划线
  "srcLang": "zh-CN",
  "distLangs": ["en-US", "zh-TW"],

  // googleApiKey
  "googleApiKey": "",

  // baiduApiKey
  "baiduApiKey":
    "appId": '',
    "appKey": ''
  },

  // 百度翻译的语种代码映射 详情见官方文档 https://fanyi-api.baidu.com/doc/21
  "baiduLangMap": {
    "en-US": 'en',
    "zh-TW": 'cht'
  },

  // 批量提取文案时生成key值时的默认翻译源, Google/Baidu/Pinyin
  "defaultTranslateKeyApi": 'Pinyin',

  // import 语句,不同项目请自己配置
  "importI18N": "",

  // 可跳过的文件夹名或者文加名,比如docs、mock等
  "ignoreDir": "",
  "ignoreFile": ""
}

kiwi --extract

  1. 一键批量替换指定文件夹下的所有文案
# --extract [dirPath] 指定文件夹路径 
# --prefix [prefix] 指定文案前缀 I18N.xxxx
kiwi --extract [dirPath] --prefix [prefix]
  1. commit 提交时自动增量提取,在 precommit 脚本内添加如下指令
# 检测提交中是否存在ts或tsx文件
TS_CHANGED=$(git diff --cached --numstat --diff-filter=ACM | grep -F '.ts' | wc -l)

# 对提交的代码中存在未提取的中文文案统一处理
if [ "$TS_CHANGED" -gt 0 ]
then
  TS_FILES_LIST=($(git diff --cached --name-only --diff-filter=ACM | grep -F '.ts'))
  TS_FILES=''
  delim=''
  for item in ${TS_FILES_LIST[@]};do
    TS_FILES=$TS_FILES$delim$item;
    delim=','
  done
  echo "\033[33m 正在检测未提取的中文文案,请稍后 \033[0m"
  kiwi --extract $TS_FILES || exit 1
fi

批量替换

kiwi --import

导入翻译文案,将翻译人员翻译的文案,导入到项目中

# 导入送翻后的文案
kiwi --import [filePath] en-US

kiwi --export

导出未翻译的文案

# 导出指定语言的文案,lang取值为配置中distLangs值,如en-US导出还未翻译成英文的中文文案
kiwi --export [filePath] en-US

kiwi --sync

同步各种语言的文案,同步未翻译文件

kiwi --mock

使用 Google 翻译,翻译未翻译的文案 如果同时配置 baiduApiKey 与 baiduApiKey 则命令行可手动选择翻译源

kiwi --translate

全量翻译未翻译的中文文案,翻译结果自动导入 en-US zh-TW 等目录

kiwi --translate