← 返回 Skills 市场
jeyeshield

json文件翻译

作者 JEyeshield · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
108
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install json-translator
功能描述
翻译JSON文件中的文本内容,特别是description字段。当用户提到需要翻译JSON文件、翻译JSON中的字段内容、翻译description字段,或者需要将JSON文件翻译成其他语言时,使用此技能。这个技能非常适合处理产品描述、API文档、配置文件、数据集等需要多语言翻译的JSON内容。
使用说明 (SKILL.md)

JSON 文件翻译助手

翻译 JSON 文件中的指定字段(默认为 description),支持多种语言互译,并保持原始 JSON 结构完整。

核心功能

  • 智能字段识别:自动查找 JSON 中的目标字段(默认 description),支持自定义指定多个字段
  • 多语言支持:支持中文、英文、日文、韩文四种语言的互译
  • 真实翻译 API:集成 MyMemory 和 LibreTranslate 两个在线翻译服务
  • 进度反馈:显示翻译进度和当前处理的字段内容
  • 结构保持:只翻译目标字段,保持 JSON 结构和其他字段不变
  • 错误处理:翻译失败时保留原文并添加标记,不会中断整个翻译过程
  • 文件导出:提供翻译后的 JSON 文件下载和结果展示

工作流程

1. 读取用户需求

先理解用户需要翻译的内容:

  • JSON 文件的路径
  • 需要翻译的字段名(默认 description,可指定多个逗号分隔)
  • 源语言和目标语言
  • 是否需要查看翻译结果或直接下载文件

2. 调用翻译脚本

使用技能目录中的 scripts/translate_json.py 脚本进行翻译:

python scripts/translate_json.py \x3C输入文件> --target-language \x3C语言代码> [选项]

脚本参数

参数 说明 示例
--target-language 目标语言代码 zh, en, ja, ko
--source-language 源语言代码(可选,默认 auto) zh, en, ja, koauto
--fields 要翻译的字段名(逗号分隔,可选) name,description
--output 输出文件路径(可选) output.json

支持的语言代码

语言代码 语言名称
zh 中文(简体)
en 英文
ja 日文
ko 韩文

3. 查看翻译结果

脚本执行后会显示:

  • 翻译进度(当前/总数)
  • 原文和译文预览
  • 翻译统计信息
  • 输出文件路径

4. 下载翻译后的文件

翻译完成后:

  • 控制台会显示输出文件路径
  • 用户可以下载该文件查看完整内容
  • 可以选择性地将结果返回给用户

使用示例

示例 1:翻译 description 字段到中文

用户说: "帮我翻译这个 JSON 文件的 description 字段到中文"

python scripts/translate_json.py data.json --target-language zh

示例 2:翻译多个字段到英文

用户说: "把这个 JSON 文件的 name 和 description 字段翻译成英文"

python scripts/translate_json.py data.json --target-language en --fields name,description

示例 3:指定源语言翻译

用户说: "将这个文件从中文翻译成日文"

python scripts/translate_json.py data.json --target-language ja --source-language zh

示例 4:指定输出文件

用户说: "翻译这个文件,输出到 translation.json"

python scripts/translate_json.py data.json --target-language en --output translation.json

输出说明

控制台输出

脚本执行时会在控制台显示:

  • [当前/总数] - 翻译进度
  • 字段路径 - 当前正在翻译的字段位置
  • 原文预览 - 50个字符
  • 译文预览 - 50个字符
  • 完成信息 - 翻译成功/失败统计

文件输出

  • 默认文件名格式:{原文件名}_translated.json
  • 用户也可以通过 --output 参数指定输出路径
  • JSON 文件保持原始缩进格式,使用 UTF-8 编码

错误处理

脚本会处理以下错误情况:

  • JSON 文件格式错误 - 显示错误信息并退出
  • 文件不存在 - 提示文件路径错误
  • 字段不存在 - 显示警告信息但继续处理
  • 翻译失败 - 保留原文并添加错误标记

注意事项

  1. API 限流:脚本会自动在每次翻译之间添加 0.1 秒延迟,避免 API 限流
  2. 大文件处理:建议 JSON 文件大小不超过 10MB
  3. 网络要求:需要能够访问 MyMemory API (https://api.mymemory.translated.net)
  4. 字段存在性:如果指定的字段在 JSON 中不存在,会提示缺失字段但继续处理其他字段
  5. 结构保持:只翻译目标字段,其他字段和 JSON 结构完全保持不变
  6. 依赖:需要安装 requests 库(脚本会自动处理,如果未安装会提示)

技术实现

翻译服务

脚本使用 MyMemory 作为主要翻译服务,LibreTranslate 作为备用服务:

  • MyMemory:免费在线翻译 API,主要翻译服务
  • LibreTranslate:开源机器翻译 API,作为备用服务
  • 自动降级:主服务失败时自动切换到备用服务
  • 错误处理:API 失败时保留原文并添加标记

字段查找

脚本使用深度递归算法查找 JSON 中的目标字段:

  • 递归遍历所有对象和数组
  • 识别指定字段名
  • 记录字段路径和值
  • 保持原始 JSON 结构

进度反馈

脚本提供实时翻译进度:

  • 显示当前翻译的字段编号
  • 显示字段路径和内容预览
  • 显示翻译状态(成功/失败)
  • 显示完成统计信息
安全使用建议
This skill generally does what it says (translate JSON fields) and doesn't request credentials, but it has implementation inconsistencies and bugs you should be aware of before using it on important data: - The SKILL.md and README advertise a LibreTranslate fallback and automatic handling of missing dependencies; the included script only calls MyMemory via the 'requests' library and doesn't implement the advertised fallback or auto-install. Expect only MyMemory to be used. - The field-detection logic can incorrectly report target fields as "missing" when those fields exist nested inside objects/arrays, causing the script to abort or skip translations unintentionally. Test the script on representative sample files. - The script requires outbound network access to https://api.mymemory.translated.net and the 'requests' package; run it in an environment where such network access is acceptable and where you can install Python dependencies safely. Recommendations: run the script on non-sensitive sample JSON first, verify behavior and outputs, and if you plan to rely on it, request fixes from the author (implement actual fallback to LibreTranslate, or correct the 'existing_fields' check so nested fields are detected correctly). If you need offline or private translations, do not use this public-API-based script.
能力评估
Purpose & Capability
Name/description and the provided script align: the tool translates specified JSON string fields (default 'description') using an online API and writes a translated JSON. Nothing in the metadata requests unrelated credentials or system access. However, SKILL.md and README claim use of two translation services (MyMemory + LibreTranslate) and 'automatic downgrade' behavior; the script only calls MyMemory. This mismatch between claimed capability and actual implementation is unexpected.
Instruction Scope
SKILL.md instructs the agent to run scripts/translate_json.py and describes recursive field detection and fallback translation. The script does perform recursive traversal and console progress output, but its logic for detecting whether target fields exist is flawed: find_all_fields() records full dotted paths (e.g. 'parent.description') and SKILL.md then uses membership checks against plain field names (e.g. 'description'), which can cause the script to report a field as 'missing' for nested occurrences even though find_fields_by_name() would find them. SKILL.md also states a LibreTranslate fallback and that the script will 'automatically handle' missing requests library; the code does not implement a LibreTranslate fallback and does not auto-install dependencies — only uses MyMemory via requests. The script requires network access to api.mymemory.translated.net, which the documentation explicitly notes.
Install Mechanism
There is no install spec; this is instruction-only with a bundled Python script. No downloads, custom installers, or external binaries are declared. The only runtime dependency is the 'requests' Python library, which the README/SKILL.md mention but the package does not auto-install.
Credentials
The skill requests no environment variables, no credentials, and no config paths. Its network access is limited to public translation API endpoints (MyMemory). No secrets or unrelated services are requested.
Persistence & Privilege
always is false and the skill does not request persistent agent-wide privileges. The script writes only the output JSON file supplied or generated in the same directory; it does not modify other skills or agent configuration.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install json-translator
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /json-translator 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
json-translator v1.0.0 - 新技能发布,提供 JSON 文件字段文本的自动翻译,尤其适用于 description 等字段。 - 支持指定多个字段、多语种互译(中、英、日、韩)、并保持 JSON 结构不变。 - 集成 MyMemory 和 LibreTranslate 双翻译 API,自动分流及错误降级。 - 翻译进度、原文与译文预览、统计信息实时反馈。 - 支持指定源/目标语言、输出文件名及多字段批量翻译。 - 强化错误处理,翻译失败字段自动标记且不中断全流程。
元数据
Slug json-translator
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

json文件翻译 是什么?

翻译JSON文件中的文本内容,特别是description字段。当用户提到需要翻译JSON文件、翻译JSON中的字段内容、翻译description字段,或者需要将JSON文件翻译成其他语言时,使用此技能。这个技能非常适合处理产品描述、API文档、配置文件、数据集等需要多语言翻译的JSON内容。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 108 次。

如何安装 json文件翻译?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install json-translator」即可一键安装,无需额外配置。

json文件翻译 是免费的吗?

是的,json文件翻译 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

json文件翻译 支持哪些平台?

json文件翻译 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 json文件翻译?

由 JEyeshield(@jeyeshield)开发并维护,当前版本 v1.0.0。

💬 留言讨论