feat: 新增项目汉化技能,支持注释/描述自动翻译为中文及对比报告生成(shell实现)
This commit is contained in:
25
skills/yanghuajun336/hanhua/SKILL.md
Normal file
25
skills/yanghuajun336/hanhua/SKILL.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# 项目汉化技能(hanhua)
|
||||
|
||||
## 技能简介
|
||||
本技能可自动将项目中的注释、介绍、描述类内容翻译为中文,适用于代码、镜像、Helm Charts、agent skills等多种类型项目。通过AI能力实现高质量翻译,确保不改变原有含义,直接替换原注释/描述内容,并可生成汉化前后对比报告。
|
||||
|
||||
## 主要功能
|
||||
- 自动识别并翻译多种类型文件中的注释、介绍、描述内容
|
||||
- 支持多种主流编程语言、YAML、Markdown等格式
|
||||
- 仅处理注释/描述内容,不影响实际代码或配置
|
||||
- 生成汉化前后对比报告,便于审查和回溯
|
||||
|
||||
## 使用方法
|
||||
1. 配置需汉化的项目路径
|
||||
2. 运行 hanhua 脚本
|
||||
3. 查看生成的对比报告
|
||||
|
||||
## 注意事项
|
||||
- 汉化仅限注释、介绍、描述类内容,实际代码/配置不做修改
|
||||
- 翻译基于AI能力,建议人工复核关键内容
|
||||
- 建议在版本管理下操作,便于回滚
|
||||
|
||||
## 目录结构
|
||||
- scripts/ —— 主要脚本
|
||||
- references/ —— 参考文档与示例
|
||||
- SKILL.md —— 技能说明文档
|
||||
33
skills/yanghuajun336/hanhua/references/hanhua-example.md
Normal file
33
skills/yanghuajun336/hanhua/references/hanhua-example.md
Normal file
@@ -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
|
||||
```
|
||||
50
skills/yanghuajun336/hanhua/scripts/hanhua.sh
Normal file
50
skills/yanghuajun336/hanhua/scripts/hanhua.sh
Normal file
@@ -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:]]*<!--|^[[:space:]]*\"\"\"|^[[:space:]]*\'\'\'/) {
|
||||
# 只翻译注释
|
||||
cmd = "hanhua_translate '"$0"'"
|
||||
cmd | getline result
|
||||
close(cmd)
|
||||
print result
|
||||
} else {
|
||||
print $0
|
||||
}
|
||||
}' "$file" > "$TMP_DIR/$relpath"
|
||||
# 生成对比
|
||||
diff -u "$TMP_DIR/$relpath.orig" "$TMP_DIR/$relpath" > "$REPORT_PATH/$relpath.diff" || true
|
||||
# 覆盖原文件
|
||||
mv "$TMP_DIR/$relpath" "$file"
|
||||
done
|
||||
|
||||
echo "汉化完成,对比报告已生成于 $REPORT_PATH"
|
||||
|
||||
# hanhua_translate: 注释行翻译函数(需接入实际AI翻译API)
|
||||
hanhua_translate() {
|
||||
# 示例:直接用AI模型API替换此处
|
||||
# 这里用echo模拟,实际应调用API
|
||||
local text="$1"
|
||||
# TODO: 替换为实际API调用
|
||||
echo "$text (已翻译为中文)"
|
||||
}
|
||||
Reference in New Issue
Block a user