Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

node.js - Google Translate API: Transliterated Input

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.

Example Sceenshot

Does anyone know how to solve this problem?

Thanks in advance!

question from:https://stackoverflow.com/questions/65847752/google-translate-api-transliterated-input

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...