From e1fdfa83ac5b50bb3900b767423cbb6ace685508 Mon Sep 17 00:00:00 2001 From: yanghuajun336 Date: Sat, 28 Mar 2026 23:44:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=B1=89=E5=8C=96=E6=8A=80=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=B3=A8=E9=87=8A/=E6=8F=8F=E8=BF=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E4=B8=BA=E4=B8=AD=E6=96=87=E5=8F=8A=E5=AF=B9?= =?UTF-8?q?=E6=AF=94=E6=8A=A5=E5=91=8A=E7=94=9F=E6=88=90=EF=BC=88shell?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- skills/yanghuajun336/hanhua/SKILL.md | 25 ++++++++++ .../hanhua/references/hanhua-example.md | 33 ++++++++++++ skills/yanghuajun336/hanhua/scripts/hanhua.sh | 50 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 skills/yanghuajun336/hanhua/SKILL.md create mode 100644 skills/yanghuajun336/hanhua/references/hanhua-example.md create mode 100644 skills/yanghuajun336/hanhua/scripts/hanhua.sh diff --git a/skills/yanghuajun336/hanhua/SKILL.md b/skills/yanghuajun336/hanhua/SKILL.md new file mode 100644 index 0000000..243b33f --- /dev/null +++ b/skills/yanghuajun336/hanhua/SKILL.md @@ -0,0 +1,25 @@ +# 项目汉化技能(hanhua) + +## 技能简介 +本技能可自动将项目中的注释、介绍、描述类内容翻译为中文,适用于代码、镜像、Helm Charts、agent skills等多种类型项目。通过AI能力实现高质量翻译,确保不改变原有含义,直接替换原注释/描述内容,并可生成汉化前后对比报告。 + +## 主要功能 +- 自动识别并翻译多种类型文件中的注释、介绍、描述内容 +- 支持多种主流编程语言、YAML、Markdown等格式 +- 仅处理注释/描述内容,不影响实际代码或配置 +- 生成汉化前后对比报告,便于审查和回溯 + +## 使用方法 +1. 配置需汉化的项目路径 +2. 运行 hanhua 脚本 +3. 查看生成的对比报告 + +## 注意事项 +- 汉化仅限注释、介绍、描述类内容,实际代码/配置不做修改 +- 翻译基于AI能力,建议人工复核关键内容 +- 建议在版本管理下操作,便于回滚 + +## 目录结构 +- scripts/ —— 主要脚本 +- references/ —— 参考文档与示例 +- SKILL.md —— 技能说明文档 diff --git a/skills/yanghuajun336/hanhua/references/hanhua-example.md b/skills/yanghuajun336/hanhua/references/hanhua-example.md new file mode 100644 index 0000000..eced78e --- /dev/null +++ b/skills/yanghuajun336/hanhua/references/hanhua-example.md @@ -0,0 +1,33 @@ +# 汉化技能示例 + +## 示例前 +```python +# This function adds two numbers +def add(a, b): + return a + b +``` + +## 示例后 +```python +# 此函数用于将两个数字相加 +def add(a, b): + return a + b +``` + +--- + +## YAML 示例前 +```yaml +# Default values for my chart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +``` + +## YAML 示例后 +```yaml +# 我的 chart 的默认值。 +# 这是一个 YAML 格式的文件。 +# 声明要传递到模板中的变量。 +replicaCount: 1 +``` diff --git a/skills/yanghuajun336/hanhua/scripts/hanhua.sh b/skills/yanghuajun336/hanhua/scripts/hanhua.sh new file mode 100644 index 0000000..b47bb00 --- /dev/null +++ b/skills/yanghuajun336/hanhua/scripts/hanhua.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# hanhua.sh +# 用于自动汉化项目中的注释、介绍、描述类内容 +# 依赖:curl(用于调用AI翻译API),diff(生成对比报告),jq(如API返回JSON) +# 用法:./hanhua.sh <目标目录> <对比报告输出路径> + +set -e + +TARGET_DIR="$1" +REPORT_PATH="$2" +TMP_DIR="/tmp/hanhua_$$" +mkdir -p "$TMP_DIR" + +if [[ -z "$TARGET_DIR" || -z "$REPORT_PATH" ]]; then + echo "用法: $0 <目标目录> <对比报告输出路径>" + exit 1 +fi + +# 递归查找常见注释文件和代码文件 +find "$TARGET_DIR" -type f \( -name '*.py' -o -name '*.js' -o -name '*.ts' -o -name '*.go' -o -name '*.java' -o -name '*.sh' -o -name '*.yaml' -o -name '*.yml' -o -name '*.md' -o -name 'Dockerfile' \) | while read file; do + relpath="${file#$TARGET_DIR/}" + cp "$file" "$TMP_DIR/$relpath.orig" + # 只处理注释和描述行,调用AI翻译API(此处用函数mock_translate模拟,实际可接入API) + awk '{ + if ($0 ~ /^[[:space:]]*#|^[[:space:]]*\/\/|^[[:space:]]*\/\*|^[[:space:]]*\*|^[[:space:]]*--|^[[:space:]]*;|^[[:space:]]*REM |^[[:space:]]*