google document:https://cloud.google.com/translate/docs/advanced/glossary#v3
I am currently using Google Glossary Translate.
I added a glossary and the content is
{
"glossaryEntries": [
{
"name": "projects/521859549804/locations/us-central1/glossaries/test-1-zh-CN-en/glossaryEntries/719985033120439992",
"termsSet": {
"terms": [
{
"languageCode": "zh-CN",
"text": "叶新"
},
{
"languageCode": "en",
"text": "Sammy Yare"
}
]
}
}
]
}
I translate text with a glossary, the translation content added is
function getContent(){
return '
这么维护叶新”
叶新朝它
叶新冲过去
叶新乐呵呵
';
}
The result is
{
"translations": [
{
"translatedText": "rnSeeing Long Yalin defending Ye Xin so much, she let go of Ye Xin, and then said to Ye Xin: "Ye Xin, right? Remember my name! My name is Li Tianyu!" Ye Xin shot at it. Ye Xin rushed over and hugged her. Ye Xin was happy.rn"
}
],
"glossaryTranslations": [
{
"translatedText": "rnSeeing Long Yalin defending Sammy Yare so much, she let go of Sammy Yare, and then said to Sammy Yare: "Sammy Yare, right? Remember my name! My name is Li Tianyu!" Ye Xin shot at it. Ye Xin rushed over and hugged her. Ye Xin was happy.rn",
"glossaryConfig": {
"glossary": "projects/521859549804/locations/us-central1/glossaries/test-1-zh-CN-en"
}
}
]
}
It is obvious to see
- “叶新朝它” is translated into “Ye Xin shot at it”
- “叶新冲过去” is translated into “Ye Xin rushed over and hugged her”
- “叶新乐呵呵” is translated into “Ye Xin was happy”
What I want should be
- “叶新朝它” is translated into “Sammy Yare shot at it”
- “叶新冲过去” is translated into “Sammy Yare rushed over and hugged her”
- “叶新乐呵呵” is translated into “Sammy Yare was happy”
Only the first translation is correct.
The execution code is as follows
function curlTranslateText($glossaryId,$contents,$sourceLanguageCode,$targetLanguageCode){
$url = 'https://translation.googleapis.com/v3/projects/'.$GLOBALS["projectId"].'/locations/us-central1:translateText';
$data = [
"sourceLanguageCode" => $sourceLanguageCode,
"targetLanguageCode" => $targetLanguageCode,
"contents" => $contents,
"glossaryConfig" => [
"glossary" => "projects/".$GLOBALS["projectId"]."/locations/us-central1/glossaries/".$glossaryId,
"ignoreCase" => false,
]
];
$res = google_auth_curl($url,"POST",json_encode($data),getHeader());
echo $res;
exit();
}
How should I set up this kind of problem?
How to prioritize glossary content during translation