部分文件格式支持内联注释,Lingo.dev CLI 会将这些注释一并带入翻译请求中。它们能为 AI 模型补充上下文——消除歧义、明确语气,或说明内容在 UI 中的显示位置。
为什么翻译注释很重要#
“Records” 既可能指病历、唱片,也可能指数据库记录。缺少上下文时,AI 模型只能靠猜。翻译注释可以消除这种歧义:
jsonc
{
// Medical context: refers to patient medical records
"records": "Records"
}注释会随字符串一起发送到翻译请求中,帮助模型朝正确的方向理解含义。
支持的格式#
目前,以下格式支持翻译注释:
| 格式 | Bucket 类型 | 注释语法 |
|---|---|---|
| JSONC | jsonc | 位于键上方的 // comment |
| Xcode String Catalogs | xcode-xcstrings | .xcstrings 文件中的注释字段 |
JSONC 示例#
jsonc
{
// Navigation menu item - appears in the top header bar
"nav.home": "Home",
// Button label - triggers form submission, keep it short
"form.submit": "Submit",
// "Light" refers to the visual theme, not weight or illumination
"settings.theme.light": "Light"
}如需使用 JSONC,请在你的 i18n.json 中配置 jsonc Bucket 类型:
json
{
"buckets": {
"jsonc": {
"include": ["locales/[locale].jsonc"]
}
}
}如何写出有效的注释#
有效的翻译注释,应补充那些无法仅从字符串本身直接看出的上下文:
| 有效示例 | 原因 |
|---|---|
// Button label in checkout flow | 让模型了解文案在 UI 中的位置,以及对简洁度的要求 |
// "Set" means a collection, not the verb | 明确多义词的具体含义 |
// Formal tone - displayed in legal footer | 明确语体风格要求 |
如果注释只是重复字符串本身(// This says Welcome),就没有额外价值。
