Android Question Do you speak Русский?

johnmie

Active Member
Licensed User
Longtime User
My app allows users to translate titles and descriptions in downloaded documents between languages using Google Translate.
This works fine between "normal" European languages but I have a problem with Russian (and I guess with any language that uses character codes beyond UTF8). While I can get English text translated to Russian, I have not (yet) found the trick to do Russian to English.

English to Russian
I send "https://Translate.googleapis.com/translate_a/single","client=gtx&sl=en&tl=ru&dt=t&q=Gray's Anatomy. This is the printed version of the 20th edititon (1918) of Gray's Anatomy, an English-language textbook of human anatomy"

and I get: "Анатомия Грея. ","Gray's Anatomy. Это печатная версия 20-го редактирования (1918 г.) «Анатомия Грея», англоязычного учебника по анатомии человека. "

German to English
I send "https://Translate.googleapis.com/translate_a/single","Max und Moritz Buch. Ein Klassiker der deutschen Kinderliteratur. In sieben Streichen ärgern die zwei Jungen die Mitbewohner ihres Dorfes. Gott sei Dank! Nun ist's vorbei mit der Übeltäterei!"

and I get: "Max and Moritz book. A classic of German children's literature. In seven strokes, the two boys annoy the roommates of their village. Thank God! Now it's over with the malaise!"

French to Russian
I send "https://Translate.googleapis.com/translate_a/single","La maîtrise de l’information passe par l’information maîtrisée."

and I get "Контроль информации проходит через контролируемую информацию. "

One can debate the quality of the translations, but at least the user gets the gist of it.


Russian to English (using su.EncodeUrl(iString,"UTF16") before sending and upon su.DecodeURL(iString,"UTF16") upon return)
I send "https://Translate.googleapis.com/translate_a/single","client=gtx&sl=ru&tl=en&dt=t&q=Африка к Югу от Сахары Развитие эпидемии СПИДа Pегиональное резюме."

and I get ""РђС \"СЂРёРєР ° Рє Югу РѕС, РЎР ° С ... Р ° СЂС \u003cР Р ° Р ·...." in return - totally useless

I tried different decodings including bytes to string (although I don't fully understand how this is supposed to work).

Does anyone know where I goofed up. Your helps is greatly appreciated. Thank you,
john m.
 

johnmie

Active Member
Licensed User
Longtime User
1. SEND:
'poststr = "https://Translate.googleapis.com/translate_a/single"
'keystring = 'client=gtx&sl=ru&tl=en&dt=t&q=Африка к Югу от Сахары Развитие эпидемии СПИДа Pегиональное резюме."

Sub UeberSetz(iString)
Dim Job1 As HttpJob
Job1.Initialize("Translate", Me)
Log("SEND TRANS 1: "&S.KeyString(iString))
Job1.PostString(S.poststr, S.keystring(iString))
End Sub

2. RETURN:
'job.GetString = [[["РђС \"СЂРёРєР ° Рє Югу РѕС, РЎР ° С ... Р ° СЂС \u003cР Р ° Р · РІРёС,РёРμ СЌРїРєРμРμРјРёРёРё РЎРџР Р\" Р ° РРμРіРёРѕРЅР ° Р »СЊРЅРѕРμ СЂРμР · СЋРјРμ.","Африка Рє Югу РѕС‚ Сахары Развитие эпидемии СПРДа Pегиональное резС��РјРµ.",null,null,3]],null,"ru"]
'TransPars extract just the useful parts

Sub JobDone(Job As HttpJob
if Job.JobName="Translate" Then
Log("translated 1 = "&Job.GetString)
A=S.TransPars(Job.GetString)
end if
end sub

3. DOING IT ONLINE
using Goggle Translate in my browser I get "Sub-Saharan Africa Developing the AIDS Epidemic Regional Summary" (which is more or less correct), but first Google asked
"Did you mean: Африка к Югу от Сахары Развитие эпидемии СПИДа Региональное резюме" (and I could not see the difference).

I tried (almost) all character sets in Klaus's book on page 366. How to decode the returned string correctly?

john m.
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
I have read somewhere that google returns a json string but I don't know how to catch and interpret it.
Using getString2("UTF16") returns gibberish 4 times as long as it should be, but decodeBase64 is not the answer either.

For now I am opening google.translate in a webview and the user has to click on the COPY button if he is happy with the translation.
That works fine if he is online, but even after downloading an offline version form google, my startActivity(intent) does not find it.

What would be the right intent.SetType or the right intent.WrapAsIntentChooser for an off-line translation app?

Any ideas?
john m.
 
Upvote 0
Top