How to use Google Translate in Matlab?
Asked Answered
P

1

7

I am writing a program to list all unique words in a movie subtitle file using Matlab. Now I have a unique word list that I want to translate to my language and learn the meaning before watching the movie.

Does anyone know how can I use Google Translate in Matlab so that I can complete my script? Is there any web service or so, and how can I use it in Matlab?

Thanks,


Appendix 1: I have found this code useful:

%build url and send to google
url = 'http://ajax.googleapis.com/ajax/services/language/translate';
page = urlread(url, 'get', {'v', '1.0','q', inputString,'langpair', [sourceLanguage '|' destLanguage]});

but I don't know why it returns error each time I run it (e.g. 403 or 400). I know that my internet connection is okay when testing.

Preinstruct answered 19/5, 2017 at 9:4 Comment(6)
There are multiple software around the internet. You could always use those and make MATLAB call those software and catch the output. Or you could learn how do they do it and replicate it in MATLABPatin
the syntax to call the webpage is simple, but how to get the translation out is not clear to me web(https://translate.google.com/#en/en/rabbit) opens a webpage in matlabJilolo
@AnderBiguri please note the appendix above I wrote, I don't understand the error!Preinstruct
@Jilolo please note the appendix above I wrote, I don't understand the error!Preinstruct
You may get the error because Google changed their API to v2. Also, can you access the API? You may need to set it up first: cloud.google.com/translate/docs/getting-started?csw=1Chemar
@Jon , Thanks for your answer. Is there any other way like above to use a web based service instead of setting up an SDK? I have problem signing up.Preinstruct
C
2

For a simple translator (I have no idea about quality), maybe try this. I didn't bother parsing the output:

langCodes = urlread('http://www.transltr.org/api/getlanguagesfortranslate'); % find your language code

textToTranslate = 'rabbit'; %change

langCodeOfOrigText ='en';
langCodeOfTranslation ='es';

translateURL = 'http://www.transltr.org/api/translate';
translateResults = urlread(translateURL, 'get', {'text',textToTranslate,'to',langCodeOfTranslation,'from',langCodeOfOrigText});

Just see next to translationText of the output for the result. Like I said, you can parse it, just google for a json to matlab struct parser.

Chemar answered 19/5, 2017 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.