Skip to content

translate result

文本翻译插件翻译成功之后,需要将数据组装为以下结构,以便 Bob 解析展示。如果只回传翻译结果,数据结构并不复杂,但是如果加上词典结果,会复杂不少,具体如下

属性类型说明
fromParagraphsarray原文分段拆分过后的 string 数组,可不传。
toParagraphsarray译文分段拆分过后的 string 数组。toParagraphs 和 toDict 至少要有一个有值。
toDictobject词典结果,见 to dict object。toParagraphs 和 toDict 至少要有一个有值。
fromstring由翻译接口提供的源语言,可以与查询时的 from 不同。查看 语言代码。可不传。
tostring由翻译接口提供的目标语言,可以与查询时的 to 不同。查看 语言代码。可不传。
fromTTStts result原文的语音合成数据,如果没有,可不传。
toTTStts result译文的语音合成数据,如果没有,可不传。
rawany如果插件内部调用了某翻译接口,可将接口原始数据传回,方便定位问题,可不传。

Bob 1.6.0 之前的版本,翻译结果中 toParagraphs 属性必须有值,其他属性有更好,没有也不影响。

Bob 1.6.0 及之后的版本,翻译结果中 toParagraphstoDict 任意一个有值即可。

一般来说 toParagraphs 返回的应该是翻译结果根据换行符分割之后的 string 数组,Bob 在展示拼接时会自动在每个 string 元素中间插入空行。

但是如果是 OpenAI 类型的插件,部分情况下可能希望保留格式,不想要插入空行,此时可以不对 string 做分割,仅给 toParagraphs 数组设置一个元素,把完整的 string 直接回传给 Bob,Bob 此时不会自动插入空行

除此之外,请尽量按照上述规范分割,以保证显示上统一。

to dict object

该对象用于描述词典结果,相对比较复杂。

属性类型说明
wordstring单词/词组,一般英文查词会有。 Bob 0.6.0+ 可用
phoneticsarray音标数据数组,一般英文查词会有,见 phonetic object
partsarray词性词义数组,一般英文查词会有,见 part object
exchangesarray其他形式数组,一般英文查词会有,见 exchange object
relatedWordPartsarray相关的单词数组,一般中文查词会有,表示和该中文对应的英文单词有哪些,见 related word part object
additionsarray附加内容数组,考虑到以上字段无法覆盖所有词典内容,比如例句、记忆技巧等,可将相应数据添加到该数组,最终也会显示到翻译结果中,见 addition object

phonetic object

该对象用于描述音标。

属性类型说明
typestring音标类型,值可以是 usuk,分别对应美式音标和英式音标。
valuestring音标字符串。例如 ɡʊd
ttstts result音标发音数据。

其中 type 为必须包含的字段,valuetts 至少包含一个。

part object

该对象用于描述某单词的词性和词义。

属性类型说明
partstring单词词性,例如 n.vi....
meansarray词义 string 数组。

exchange object

该对象用于描述某单词的其他形式。

属性类型说明
namestring形式的名字,例如 比较级最高级...
wordsarray该形式对于的单词 string 数组,一般只有一个

该对象用于描述一组与所查询的文本相关的单词,分组的标准为词性。

属性类型说明
partstring词性。
wordsarray相关的单词数组,见 related word object

如果无法获取,part 可以不传,但 words 中至少要有一个元素。

该对象用于描述一个单词。

属性类型说明
wordstring单词本身。
meansarray词义 string 数组。

word 必须有值,means 可以不传。

addition object

该对象用于描述一段附加内容。

属性类型说明
namestring附加内容名称。
valuestring附加内容。

示例

内容较长,内附 JSON 对应的效果图,请点击展开:

翻译「good」的示例
json
{
    "from": "en",
    "to": "zh-Hans",
    "fromParagraphs": [
        "good"
    ],
    "toParagraphs": [
        "好"
    ],
    "toDict": {
        "word": "good",
        "phonetics": [
            {
                "type": "us",
                "value": "ɡʊd",
                "tts": {
                    "type": "url",
                    "value": "http://xxxxxxxxxx..."
                }
            },
            {
                "type": "uk",
                "value": "ɡʊd",
                "tts": {
                    "type": "url",
                    "value": "http://xxxxxxxxxx..."
                }
            }
        ],
        "parts": [
            {
                "part": "adj.",
                "means": [
                    "好的",
                    "优良的",
                    "愉快的",
                    "虔诚的"
                ]
            },
            {
                "part": "n.",
                "means": [
                    "好处",
                    "善行",
                    "慷慨的行为"
                ]
            },
            {
                "part": "adv.",
                "means": [
                    "好"
                ]
            },
            {
                "part": "n.",
                "means": [
                    "(Good)人名",
                    "(英)古德",
                    "(瑞典)戈德"
                ]
            }
        ],
        "exchanges": [
            {
                "name": "比较级",
                "words": [
                    "better"
                ]
            },
            {
                "name": "最高级",
                "words": [
                    "best"
                ]
            },
            {
                "name": "复数",
                "words": [
                    "goods"
                ]
            }
        ],
        "additions": [
            {
                "name": "标签",
                "value": "初中/高中/CET4/CET6/考研"
            }
        ]
    },
    "fromTTS": {
        "type": "url",
        "value": "http://xxxxxxxxxx..."
    },
    "toTTS": {
        "type": "url",
        "value": "http://xxxxxxxxxx..."
    },
    "raw": {}
}
{
    "from": "en",
    "to": "zh-Hans",
    "fromParagraphs": [
        "good"
    ],
    "toParagraphs": [
        "好"
    ],
    "toDict": {
        "word": "good",
        "phonetics": [
            {
                "type": "us",
                "value": "ɡʊd",
                "tts": {
                    "type": "url",
                    "value": "http://xxxxxxxxxx..."
                }
            },
            {
                "type": "uk",
                "value": "ɡʊd",
                "tts": {
                    "type": "url",
                    "value": "http://xxxxxxxxxx..."
                }
            }
        ],
        "parts": [
            {
                "part": "adj.",
                "means": [
                    "好的",
                    "优良的",
                    "愉快的",
                    "虔诚的"
                ]
            },
            {
                "part": "n.",
                "means": [
                    "好处",
                    "善行",
                    "慷慨的行为"
                ]
            },
            {
                "part": "adv.",
                "means": [
                    "好"
                ]
            },
            {
                "part": "n.",
                "means": [
                    "(Good)人名",
                    "(英)古德",
                    "(瑞典)戈德"
                ]
            }
        ],
        "exchanges": [
            {
                "name": "比较级",
                "words": [
                    "better"
                ]
            },
            {
                "name": "最高级",
                "words": [
                    "best"
                ]
            },
            {
                "name": "复数",
                "words": [
                    "goods"
                ]
            }
        ],
        "additions": [
            {
                "name": "标签",
                "value": "初中/高中/CET4/CET6/考研"
            }
        ]
    },
    "fromTTS": {
        "type": "url",
        "value": "http://xxxxxxxxxx..."
    },
    "toTTS": {
        "type": "url",
        "value": "http://xxxxxxxxxx..."
    },
    "raw": {}
}

效果图:

tranlate-example-1
翻译「愤怒」的示例
json
{
    "from": "zh-Hans",
    "to": "en",
    "fromParagraphs": [
        "愤怒"
    ],
    "toParagraphs": [
        "anger"
    ],
    "toDict": {
        "relatedWordParts": [
            {
                "part": "名词",
                "words": [
                    {
                        "word": "anger",
                        "means": [
                            "愤怒",
                            "怒",
                            "怒气",
                            "怒火",
                            "愤",
                            "火气"
                        ]
                    },
                    {
                        "word": "rage",
                        "means": [
                            "愤怒",
                            "怒气",
                            "怒",
                            "怒火",
                            "盛怒",
                            "忿怒"
                        ]
                    },
                    {
                        "word": "wrath",
                        "means": [
                            "愤怒",
                            "雷霆"
                        ]
                    },
                    {
                        "word": "fury",
                        "means": [
                            "愤怒",
                            "怒",
                            "暴怒",
                            "怒火",
                            "怒气",
                            "盛怒"
                        ]
                    },
                    {
                        "word": "outrage",
                        "means": [
                            "暴行",
                            "愤怒",
                            "侮辱"
                        ]
                    },
                    {
                        "word": "indignation",
                        "means": [
                            "愤慨",
                            "愤怒",
                            "义愤"
                        ]
                    },
                    {
                        "word": "pique",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "bile",
                        "means": [
                            "胆汁",
                            "愤怒",
                            "坏脾气"
                        ]
                    },
                    {
                        "word": "vehemence",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "huff",
                        "means": [
                            "愤怒",
                            "发怒"
                        ]
                    },
                    {
                        "word": "umbrage",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "teen",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "vehemency",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "paddy",
                        "means": [
                            "稻田",
                            "稻谷",
                            "稻",
                            "谷",
                            "稻子",
                            "愤怒"
                        ]
                    }
                ]
            },
            {
                "part": "形容词",
                "words": [
                    {
                        "word": "angry",
                        "means": [
                            "愤怒",
                            "生气",
                            "恼怒",
                            "恼",
                            "忿怒",
                            "忧郁"
                        ]
                    },
                    {
                        "word": "indignant",
                        "means": [
                            "愤怒",
                            "愤慨",
                            "气愤",
                            "愤愤不平",
                            "激愤",
                            "愠"
                        ]
                    },
                    {
                        "word": "raging",
                        "means": [
                            "愤怒",
                            "熊熊",
                            "炽灼的"
                        ]
                    }
                ]
            },
            {
                "part": "动词",
                "words": [
                    {
                        "word": "pique",
                        "means": [
                            "愤怒",
                            "激怒"
                        ]
                    },
                    {
                        "word": "huff",
                        "means": [
                            "愤怒",
                            "发怒"
                        ]
                    }
                ]
            }
        ]
    },
    "raw": {}
}
{
    "from": "zh-Hans",
    "to": "en",
    "fromParagraphs": [
        "愤怒"
    ],
    "toParagraphs": [
        "anger"
    ],
    "toDict": {
        "relatedWordParts": [
            {
                "part": "名词",
                "words": [
                    {
                        "word": "anger",
                        "means": [
                            "愤怒",
                            "怒",
                            "怒气",
                            "怒火",
                            "愤",
                            "火气"
                        ]
                    },
                    {
                        "word": "rage",
                        "means": [
                            "愤怒",
                            "怒气",
                            "怒",
                            "怒火",
                            "盛怒",
                            "忿怒"
                        ]
                    },
                    {
                        "word": "wrath",
                        "means": [
                            "愤怒",
                            "雷霆"
                        ]
                    },
                    {
                        "word": "fury",
                        "means": [
                            "愤怒",
                            "怒",
                            "暴怒",
                            "怒火",
                            "怒气",
                            "盛怒"
                        ]
                    },
                    {
                        "word": "outrage",
                        "means": [
                            "暴行",
                            "愤怒",
                            "侮辱"
                        ]
                    },
                    {
                        "word": "indignation",
                        "means": [
                            "愤慨",
                            "愤怒",
                            "义愤"
                        ]
                    },
                    {
                        "word": "pique",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "bile",
                        "means": [
                            "胆汁",
                            "愤怒",
                            "坏脾气"
                        ]
                    },
                    {
                        "word": "vehemence",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "huff",
                        "means": [
                            "愤怒",
                            "发怒"
                        ]
                    },
                    {
                        "word": "umbrage",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "teen",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "vehemency",
                        "means": [
                            "愤怒"
                        ]
                    },
                    {
                        "word": "paddy",
                        "means": [
                            "稻田",
                            "稻谷",
                            "稻",
                            "谷",
                            "稻子",
                            "愤怒"
                        ]
                    }
                ]
            },
            {
                "part": "形容词",
                "words": [
                    {
                        "word": "angry",
                        "means": [
                            "愤怒",
                            "生气",
                            "恼怒",
                            "恼",
                            "忿怒",
                            "忧郁"
                        ]
                    },
                    {
                        "word": "indignant",
                        "means": [
                            "愤怒",
                            "愤慨",
                            "气愤",
                            "愤愤不平",
                            "激愤",
                            "愠"
                        ]
                    },
                    {
                        "word": "raging",
                        "means": [
                            "愤怒",
                            "熊熊",
                            "炽灼的"
                        ]
                    }
                ]
            },
            {
                "part": "动词",
                "words": [
                    {
                        "word": "pique",
                        "means": [
                            "愤怒",
                            "激怒"
                        ]
                    },
                    {
                        "word": "huff",
                        "means": [
                            "愤怒",
                            "发怒"
                        ]
                    }
                ]
            }
        ]
    },
    "raw": {}
}

效果图:

tranlate-example-2
翻译句子的示例
json
{
    "from": "en",
    "to": "zh-Hans",
    "fromParagraphs": [
        "macOS Catalina gives you more of everything you love about Mac.",
        "Experience music, TV, and podcasts in three all-new Mac apps.",
        "Enjoy your favorite iPad apps now on your Mac.",
        "Extend your workspace and expand your creativity with iPad and Apple Pencil.",
        "And discover smart new features in the apps you use every day.",
        "Now you can take everything you do above and beyond."
    ],
    "toParagraphs": [
        "macOS Catalina为您提供了有关Mac的所有喜爱内容。",
        "在三个全新的Mac应用程序中体验音乐,电视和播客。",
        "立即在Mac上享受您喜爱的iPad应用程序。",
        "使用iPad和Apple Pencil扩展工作空间并扩展您的创造力。",
        "并在每天使用的应用程序中发现智能的新功能。",
        "现在,您可以将自己所做的一切超越一切。"
    ]
}
{
    "from": "en",
    "to": "zh-Hans",
    "fromParagraphs": [
        "macOS Catalina gives you more of everything you love about Mac.",
        "Experience music, TV, and podcasts in three all-new Mac apps.",
        "Enjoy your favorite iPad apps now on your Mac.",
        "Extend your workspace and expand your creativity with iPad and Apple Pencil.",
        "And discover smart new features in the apps you use every day.",
        "Now you can take everything you do above and beyond."
    ],
    "toParagraphs": [
        "macOS Catalina为您提供了有关Mac的所有喜爱内容。",
        "在三个全新的Mac应用程序中体验音乐,电视和播客。",
        "立即在Mac上享受您喜爱的iPad应用程序。",
        "使用iPad和Apple Pencil扩展工作空间并扩展您的创造力。",
        "并在每天使用的应用程序中发现智能的新功能。",
        "现在,您可以将自己所做的一切超越一切。"
    ]
}

效果图:

tranlate-example-3