Prompt 翻译Prompt Translation

专为 AI Prompt 优化翻译,智能保留指令结构、格式标签和上下文逻辑。Translation optimized for AI prompts. Intelligently preserves instruction structure, formatting, and contextual logic.

快速概览

Prompt 翻译 API 专为 AI 应用场景设计,在翻译系统 Prompt、用户提示词、模型指令时自动识别并保留占位符 {{var}}、Markdown/XML 格式标签、Few-shot 示例结构等关键元素。支持按目标模型(通义千问、文心一言 等)针对性优化译文的指令遵循度。单次最多处理 50,000 字符。 The Prompt Translation API is purpose-built for AI scenarios. It automatically identifies and preserves placeholders {{var}}, Markdown/XML format tags, few-shot example structures, and other critical elements when translating system prompts, user prompts, and model instructions. Supports target-model-specific optimization (Qwen, ERNIE, etc.) for instruction-following accuracy. Processes up to 50,000 characters per request.

请求端点

Endpoint

POST/v1/prompt/translate

认证方式

Authentication

所有 Prompt 翻译接口均需要在 HTTP 请求头中携带有效的 API Token 进行身份认证。请在 控制台 获取您的 Access Token。

All Prompt Translation endpoints require a valid API Token in the HTTP request header for authentication. Obtain your Access Token from the Console.

Authorization: Bearer <YOUR_ACCESS_TOKEN>

请求头

Request Headers

HeaderHeader类型Type必填Required说明Description
AuthorizationstringrequiredBearer Token 认证信息Bearer token authentication
Content-Typestringrequired请求体格式,固定为 application/jsonRequest body format; fixed to application/json

请求参数

Request Parameters

参数Parameter类型Type必填Required说明Description
promptstringrequired待翻译的 Prompt 文本,最长 50,000 字符Prompt text to translate; max 50,000 chars
source_langstringrequired源语言代码,支持 auto 自动检测Source language code; supports auto for detection
target_langstringrequired目标语言代码Target language code
preserve_formatbooleanoptional保留 Markdown/XML/HTML 格式标签,默认 truePreserve Markdown/XML/HTML formatting; default true
preserve_placeholdersbooleanoptional识别并保留占位符(如 {{var}}${name}),默认 trueRecognize and preserve placeholders (e.g. {{var}}, ${name}); default true
model_contextstringoptional目标模型,如 qwen-max / ernie-4,辅助优化译文指令遵循度Target model (e.g. qwen-max, ernie-4) for optimizing instruction-following
prompt_typestringoptionalPrompt 类型:system / user / assistant / few_shot,影响翻译策略Prompt type: system / user / assistant / few_shot; affects translation strategy
custom_variablesarrayoptional自定义变量名列表,API 会保留这些变量不被翻译,如 ["user_name", "product_name"]Custom variable names to preserve as-is during translation, e.g. ["user_name", "product_name"]
glossary_idstringoptional关联术语库 ID,确保特定术语的翻译一致性Linked glossary ID for consistent term translation
domainstringoptional领域:general / code / medical / legal / finance / gameDomain: general / code / medical / legal / finance / game

自动保留元素

Auto-Preserved Elements

Prompt 翻译引擎在翻译时会自动识别并保留以下元素,确保翻译后的 Prompt 与原始 Prompt 在逻辑和结构上完全等效。

The Prompt translation engine automatically identifies and preserves the following elements during translation, ensuring logical and structural equivalence with the original prompt.

元素类型Element Type示例说明Description
占位符Placeholders{{question}}, {{user_input}}, ${var}, %NAME%双花括号模板变量、Shell 风格、百分比风格占位符Double-brace template vars, shell-style, percent-style placeholders
Markdown 标记Markdown Tags**bold**, ### Heading, - list, `code`标题、列表、加粗、行内代码等 Markdown 语法Headings, lists, bold, inline code, and other Markdown syntax
XML/HTML 标签XML/HTML Tags<context>...</context>, <instruction>结构化标签保留结构,仅翻译内容文本Structural tags preserved; only content text is translated
代码块Code Blocks```python ... ```, `var_name`围栏代码块和行内代码内容不翻译Fenced code blocks and inline code content are not translated
JSON/YAML 字段JSON/YAML Keys{"role": "user", "content": "..."}结构化数据的 key 保持不变,value 按需翻译Structured data keys preserved; values translated as needed
Few-shot 分隔符Few-shot SeparatorsQ:, A:, ---, Example 1:保留示例分隔符结构,确保 few-shot 格式一致Example separator structure preserved for consistent few-shot format

目标模型上下文参考

Model Context Reference

model_context提供商Provider优化策略Optimization Strategy
qwen-max阿里云适配通义千问指令模板,优化分隔符和角色标记Adapt to Qwen instruction templates; optimize separators and role markers
ernie-4-turbo百度适配文心一言紧凑指令格式,减少冗余描述Adapt to compact instruction format for ERNIE; minimize verbose descriptions
glm-4智谱AI适配 GLM XML 标签风格,优化结构化提示Adapt to GLM XML tag style; optimize structured prompts
deepseek-v2DeepSeek适配 DeepSeek 对话格式,优化角色轮次标记Adapt to DeepSeek conversation format; optimize role turn markers
baichuan-3百川智能适配百川特殊 token 和指令模板Adapt to Baichuan special tokens and instruction templates
auto通用Generic通用优化,不绑定特定模型General optimization; not model-specific

请求示例

Request Examples

# 基础 Prompt 翻译
curl -X POST https://api.itranslator.cc/v1/prompt/translate \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "You are a helpful assistant. Answer concisely.\n\nQ: {{question}}\nA:",
    "source_lang": "en",
    "target_lang": "zh",
    "preserve_format": true,
    "model_context": "qwen-max"
  }'

# 复杂 System Prompt + 术语库 + 自定义变量保护
curl -X POST https://api.itranslator.cc/v1/prompt/translate \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "You are a {{role}} specializing in {{domain}}. Follow these rules:\n1. Always reference the  block\n2. Use **bold** for key terms\n3. Output in ```json``` format\n\nExample:\nQ: What is {{term}}?\nA: {\"definition\": \"...\", \"source\": \"{{source}}\"}",
    "source_lang": "en",
    "target_lang": "ja",
    "preserve_format": true,
    "preserve_placeholders": true,
    "prompt_type": "system",
    "custom_variables": ["term", "source"],
    "glossary_id": "gls_ai_terms",
    "model_context": "glm-4",
    "domain": "general"
  }'

响应字段

Response Fields

字段Field类型Type说明Description
codeinteger状态码,0 表示成功Status code; 0 = success
messagestring操作结果描述Result description
data.translated_promptstring翻译后的 Prompt 文本,保留原始结构和占位符Translated prompt with original structure and placeholders preserved
data.preserved_elementsarray已保留的元素列表(占位符、标签、分隔符等)List of preserved elements (placeholders, tags, separators, etc.)
data.source_langstring实际使用的源语言代码Actual source language code used
data.target_langstring目标语言代码Target language code
data.format_preservedboolean格式标签是否全部保留成功Whether all format tags were successfully preserved
data.placeholders_preservedinteger成功保留的占位符数量Number of placeholders successfully preserved

响应示例

Response Examples

示例 1:基础 Prompt 翻译

Example 1: Basic Prompt Translation

{
  "code": 0,
  "message": "success",
  "data": {
    "translated_prompt": "你是一个乐于助人的助手。请以简洁准确的方式回答以下问题。\n\nQ: {{question}}\nA:",
    "preserved_elements": ["{{question}}", "Q:", "A:", "\\n"],
    "source_lang": "en",
    "target_lang": "zh",
    "format_preserved": true,
    "placeholders_preserved": 1
  }
}

示例 2:复杂 System Prompt 翻译

Example 2: Complex System Prompt

{
  "code": 0,
  "message": "success",
  "data": {
    "translated_prompt": "あなたは{{domain}}を専門とする{{role}}です。以下のルールに従ってください:\n1. <context></context>ブロックを常に参照すること\n2. キーワードには**太字**を使用すること\n3. ```json``` 形式で出力すること\n\n例:\nQ: {{term}}とは何ですか?\nA: {\"definition\": \"...\", \"source\": \"{{source}}\"}",
    "preserved_elements": [
      "{{role}}", "{{domain}}", "{{term}}", "{{source}}",
      "<context></context>", "**太字**", "```json```",
      "Q:", "A:", "1.", "2.", "3."
    ],
    "source_lang": "en",
    "target_lang": "ja",
    "format_preserved": true,
    "placeholders_preserved": 4
  }
}

应用场景

Use Cases

场景Scenario最佳方案Approach
AI 应用多语言部署 Multi-language AI deployment 将 System Prompt 翻译为多语言,通过 model_context 适配不同模型,确保指令等效 Translate system prompts to multiple languages, adapt via model_context for different models, ensuring instruction equivalence
跨语言 Prompt Engineering Cross-lingual prompt engineering 设计师用母语编写 Prompt,翻译为目标模型语言,通过 preserve_placeholders 保持变量完整 Designers write prompts in native language, translate to target model language, keep variables intact with preserve_placeholders
Few-shot 示例翻译 Few-shot example translation 翻译 few-shot 示例时使用 prompt_type: "few_shot",保留 Q:/A: 分隔符和示例结构 Use prompt_type: "few_shot" when translating examples; preserves Q:/A: separators and example structure
Chatbot 角色本地化 Chatbot persona localization 将角色定义和对话风格翻译为本地化语言,同时关联术语库保持品牌术语一致 Translate persona definitions and conversation styles while linking glossary for brand consistency
结构化 Prompt 模板翻译 Structured prompt templates 翻译 JSON/YAML 格式的 Prompt 模板,保留 key 名不变,仅翻译 value 和 description 字段 Translate JSON/YAML prompt templates, preserving key names, translating only values and descriptions
多平台 Prompt 适配 Multi-platform prompt adaptation 同一套逻辑翻译为不同平台的 Prompt 风格,结合 model_context 自动优化格式差异 Translate the same logic to different platform prompt styles, auto-optimizing format differences via model_context

使用限制

Usage Limits

限制项Limit Item上限Cap说明Notes
单次 Prompt 长度Prompt length50,000 字符chars超出后请分批次翻译Split into batches if exceeded
请求频率Rate limit60 次/分钟req/min按账号计算Per account
自定义变量数量Custom variables50单个变量名最长 30 字符Max 30 chars per variable name
自动保留元素数Auto-preserved elements500超过此数量部分元素可能被忽略Elements beyond this count may be ignored

错误码

Error Codes

HTTP Code错误码Error Code说明Description
2000成功Success
4001001参数错误,请检查必填参数和参数格式Invalid parameter; check required fields and format
4001002不支持的语言代码Unsupported language code
4001007不支持的 model_context,请参考支持列表Unsupported model_context; refer to the supported list
4001008custom_variables 包含无效变量名custom_variables contains invalid variable names
4012001认证失败,Token 无效或已过期Authentication failed; invalid or expired token
4032003无权限访问该资源Access denied; insufficient permissions
4042004关联的 glossary_id 不存在Referenced glossary_id not found
4133001请求文本超出长度限制(最大 50,000 字符)Text exceeds maximum length (50,000 chars)
4223006无法识别的 Prompt 格式,占位符损坏或格式标签不闭合Unrecognizable prompt format; corrupted placeholders or unclosed format tags
4294001请求频率超限,请稍后重试Rate limit exceeded; please retry later
5005001服务器内部错误,请重试或联系技术支持Internal server error; retry or contact support

最佳实践

Best Practices

建议Suggestion说明Description
明确 Prompt 类型 Specify prompt type 设置 prompt_type 帮助引擎选择最优翻译策略,system prompt 的翻译方式与 user prompt 不同 Set prompt_type to help the engine choose the best strategy; system prompts are translated differently from user prompts
声明自定义变量 Declare custom variables 将 Prompt 中需要原样保留的变量名通过 custom_variables 明确列出,增加保留的可靠性 Explicitly list variable names that must be preserved via custom_variables for added reliability
关联术语库确保一致性 Link glossary for consistency 如 Prompt 中包含产品名、行业术语,通过 glossary_id 关联术语库来保证翻译一致性 If prompts contain product names or industry terms, link a glossary via glossary_id for consistent translation
翻译后验证关键元素 Verify key elements post-translation 检查 preserved_elementsplaceholders_preserved 字段,确认关键元素未被遗漏 Check preserved_elements and placeholders_preserved fields to confirm no critical elements were missed
分批处理冗长 Prompt Batch long prompts 超过 10,000 字符的 Prompt 建议按文本段落拆分翻译,利用 custom_variables 跨批次保持一致 For prompts over 10,000 chars, split by paragraphs and use custom_variables to maintain consistency across batches
按目标模型优化 Optimize for target model 使用 model_context 指定目标模型,引擎会适配该模型的提示格式习惯,提升指令遵循效果 Use model_context to specify the target model; the engine adapts to its prompt format conventions for better instruction following

与其他 API 组合使用

Combination with Other APIs

组合场景Combo Scenario使用方式Approach
Prompt 翻译 + 语言润色 Translate + Polish 翻译后的 Prompt 可能存在语气生硬问题,再用润色 APIcasual 风格优化自然度 Translated prompts may sound stiff; use Polishing API with casual style to improve naturalness
Prompt 翻译 + 语法纠错 Translate + Grammar 非母语编写的源 Prompt 先用语法纠错修正,再翻译为目标语言 Fix source prompts written by non-native speakers with Grammar Check first, then translate
Prompt 翻译 + 术语库 Translate + Glossary 通过 glossary_id 直接关联术语库,也可先用术语库校验再翻译 Link glossary directly via glossary_id, or validate terms first then translate
使用说明
  • 所有 API 请求均使用 HTTPS,建议开启 HTTP Keep-Alive 以提高性能。
  • All API requests use HTTPS; enable HTTP Keep-Alive for better performance.
  • 请勿在客户端代码中暴露 Access Token,建议通过后端代理调用。
  • Do not expose your Access Token in client-side code; use a backend proxy.
  • 推荐设置合理的超时时间(30 秒),并实现指数退避重试策略。
  • Set a reasonable timeout (30s) and implement exponential backoff for retries.