We are currently developing an application which uses the Google Translate API. For that we use the Cloud Translate Library for Node.js.
This works until the input text is transliterated (e.g. from Cyrillic -> Latin).
A translation of the russian sentence "Я хочу поговорить с сотрудником." to another language works fine but when we use the latin transliteration "YA khochu pogovorit' s sotrudnikom." the Translation API just returns the input text (which is equivalent to not translated at all).
This is what our code looks:
this.googleTranslate = new TranslationServiceClient();
...
private static performOnlineTranslation(text: string, isoFrom: string, isoTo: string, callback: Function) {
const request = {
parent: `projects/xxx/locations/global`,
contents: [text],
mimeType: 'text/plain',
sourceLanguageCode: isoFrom,
targetLanguageCode: isoTo,
};
this.googleTranslate.translateText(request)
.then((response: any[]) => {
let trans = response[0].translations[0].translatedText;
callback(trans);
});
}
We've stumbled across some solutions for modifying the target language transliteration by adding an '-Latn' to the language code but even this doesn't work for our example.
When using the online translation tool Google even offers the transliterated text and is also able to 'understand' transliterated input.
Does anyone know how to solve this problem?
Thanks in advance!
question from:
https://stackoverflow.com/questions/65847752/google-translate-api-transliterated-input 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…