This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
viluon's profile picture

Google Translate in CC

Started by viluon, 07 May 2014 - 05:48 PM
viluon #1
Posted 07 May 2014 - 07:48 PM
Hello community!

Yesterday I made a simple PHP script that behaves like a web browser and communicates with Google Translate. As the official Google Translate API is not freely available ($20/Month/1M requests) I hope that you will appreciate this!

Documentation:
Http request is formated as follows:
http://acos.bluefile.cz/translate.php?input=textToTranslate&from=originalLanguage&to=targetLanguage
Example Language codes:
en for English
de for Deutsch
fr for French
cs for Czech


Response has an advertisement on the top of the page, to deal with this the output is put between <parse></parse> tags. The output is Url-encoded to deal with encoding of language-special characters. Spaces are replaced with "+" symbols (not "%20"!!!)

Example usage:
Translating "Hello community!" from English to French:
http://acos.bluefile.cz/translate.php?input=Hello%20community!&amp;from=en&amp;to=fr
Output:
<div ><div class="souhrn">Vyzkoušejte nový webhosting <a href="http://b.cz/">b.cz</a>. Nejkratší doména 2. řádu na českém trhu.</div></div>
<parse>
Bonjour+la+communaut%C3%A9%21</parse>

You will definitely need to whitelist acos.bluefile.cz for this to work


Hope you understand, don't forget to give +1 if you like this :)/>

A very (very very very) simple example of a translator http://pastebin.com/neN7A2Aa
(It doesn't even remove the parse tags, its just to show a basic example of url decoding and request formatting)


this 100% free cross-platform implementation of Google Translate

was brought to you by AndySoft



You can use this if:
You will PM me first and ask for detailed information
You will only use the script inside CC
You will only provide the product using my script for free
You will give me the credit for this script visible inside both the program (eg sth like about tab) and the source code


Note: the server is online 24/7 and is able to handle up to 3 requests simultaneously
Edited on 08 May 2014 - 04:46 PM
TheOddByte #2
Posted 07 May 2014 - 08:40 PM
This seems very interesting! :D/> I would be happy to help creating a more advanced application of this if you'd like ;)/>
Are all languages currently available?
viluon #3
Posted 07 May 2014 - 08:59 PM
All languages that Google Translate has, yes! Thanks for positive feedback :)/>

Edit:the main use I see for this is implementing dynamically translated applications as lots of users here on the forums don't understand English much (my experience, that's why you can see eg French OS)
Edited on 07 May 2014 - 07:01 PM
viluon #4
Posted 09 May 2014 - 05:40 PM
Cool tip!

Inputting "auto" as the source language will result in automatic language detection!
Blue #5
Posted 09 May 2014 - 07:01 PM
WOW :o/> Definitely going to give a +1 to this.Now i don't have to get out of fullscreen mode on minecraft,go into my browser and then go on transalate (I'm lazy :P/> ).Also,it's faster than the regular google transalate.Alot of programs are going to be using this.Nice job :)/>
viluon #6
Posted 10 May 2014 - 11:14 AM
WOW :o/> Definitely going to give a +1 to this.Now i don't have to get out of fullscreen mode on minecraft,go into my browser and then go on transalate (I'm lazy :P/> ).Also,it's faster than the regular google transalate.Alot of programs are going to be using this.Nice job :)/>
Thanks :)/>
apemanzilla #7
Posted 11 May 2014 - 04:17 PM
This is a very cool utility. However, I would warn you that Google can - and will - block your server's IP address automatically if it thinks you're a bot. (Which, in this case, you are) While this may not be a problem right now, if it suddenly stops working for no reason, you might have been blocked.
viluon #8
Posted 11 May 2014 - 04:23 PM
The header of the requests behaves like IE, don't think Google will know :D/>
apemanzilla #9
Posted 11 May 2014 - 05:23 PM
The header of the requests behaves like IE, don't think Google will know :D/>/>
Well, I've gotten captchas while using Chrome before…
DiamondTNT #10
Posted 06 June 2014 - 09:51 PM
Does this API support non-ASCII characters?
viluon #11
Posted 06 June 2014 - 11:22 PM
It's not about the API, it's about Google. And I suppose it does :D/> the response is url encoded so there shouldn't be any problem with encoding. Give it a try, PM me if you encounter any issues.
Agent Silence #12
Posted 05 November 2014 - 06:47 PM
I could hook this up with MoarPeripherals chatbox peripheral
then i could add a custom chat handler like "@"
so i could do "@fr Hello" and have the chatbox say it in french!
Luca_S #13
Posted 18 November 2014 - 08:52 PM
Hey, may i do an API out of this(to use functions like:tanslate.trans("Hi, im a Text","en","de")) i would do a credit like this(very simple, but if you want to add something Reply :D/>)
–[
Hey! I just wanna notice that all rights of this dont belong to me, they beloung to viluon who posted this:
http://www.computerc...ranslate-in-cc/
I just made an API out of this
]–
If you would allow this to me I would publish a pastebin link here.

EDIT: Why dont you fix the <parse> </parse> bug not with:


out = out:sub(9) --#9 also removes the empty line
out = out:sub(1,#out-8)
Edited on 18 November 2014 - 07:57 PM
Luca_S #14
Posted 22 December 2014 - 02:51 PM
Ok, I have permission to post the API, it makes it easier to use this(I hope :D/>):
pastebin get QbkKzxfx translate
I think you know, that you shouldn't use this in mass, if not, read the original post!!!

The Usage is simple:


os.loadAPI("translate")
translated = translate.Translate("Text to translate,""from","to")
translated = translate.AsyncTranslate("Text to translate","from","to")

Hope I made it easier for you, to implement this.
Edited on 13 February 2015 - 01:02 PM
Engineer #15
Posted 22 December 2014 - 03:38 PM
Ok, I have permission to post the API, it makes it easier to use this(I hope :D/>/>/>):
http://pastebin.com/nkFPK853
I think you know, that you shouldn't use this in mass, if not, read the original post!!!

The Usage is simple:


os.loadAPI("translate")
translated = translate.trans("Text to translate,""From","to")

Hope I made it easier for you, to implement this.
You might need to make a buffer to be more efficient, also reduces the API call from CC to the server resulting in less calls to google
Edited on 22 December 2014 - 02:39 PM
Luca_S #16
Posted 22 December 2014 - 05:16 PM
You might need to make a buffer to be more efficient, also reduces the API call from CC to the server resulting in less calls to google

You mean something like a history? My Problem is that I don't know what you want to buffer.
Edited on 22 December 2014 - 04:39 PM