This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Peter Gr
Posted Aug 20 - Read on Facebook

I'm trying to find a way to translate text with an api. Has anyone done this?

11 Comments

Edwin Van Rijkom

Never done this myself, but this Google API seems like something that should be useable from within your prototype: https://cloud.google.com/translate

Peter Gr

Thanks Edwin. I was hoping to find a free solution

Edwin Van Rijkom

Ah, I see. Don't know any, I'm afraid. Good luck finding one!

Peter Gr

Thanks. I did find this free one, but I'm not familiar with how it would be used / implemented in Framer http://www.transltr.org/Developers

Edwin Van Rijkom

Think you'd likely be using XMLHttpRequest from inside your project. Some more info on using that from CoffeeScript is here (although the actual CS code is really badly formatted): https://coffeescript-cookbook.github.io/chapters/ajax/ajax_request_without_jquery

Peter Gr

Thanks for that! I was actually looking into ways to scrape the html of a url from a different domain. That way I could generate a google translate url that includes the text I want to translate and then just parse the html to get the translated text. But I don't have experience doing that kind of programming and didn't want to spend a whole lot of time if it's too involved

Peter Gr

From what I understand the XMLHttpRequest method only works within your own domain. Unless there's some way to use a proxy server through framer...

Edwin Van Rijkom

I think XMLHttpRequests can be cross origin (using 'CORS') - all the details should be here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Peter Gr

AWESOME!

Marc Krenn
Peter Gr

Having a bit of trouble -- I'm trying to get the html of this page:

https://translate.google.com/#es/en/hola%20mundo

I'm trying to get the "hello world" text that it produces in the 'id="result_box"' div.

Here's my code. It can get a bunch of text back from the target page, but it's different than what I'm seeing when I load the page manually.. I must be missing a step. Any ideas? If I print the xhr.responseText it gives a bunch of stuff from Google Translate, but apparently not the translation query or results

Read the entire post on Facebook