10

I need Translate API service for my app and have chosen Google Translate API, which will cost money and require authentication against the Google API. But during the search I've found this link which looks freely available and do what I need without cost:

https://translate.google.so/translate_a/t?client=any_client_id_works&sl=auto&tl=ru&q=wrapper&tbb=1&ie=UTF-8&oe=UTF-8

Try to issue a GET request and you'll see it by yourself.

So, my question is what is the difference between these above services and am I authorized to use the second one?

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
Anatoly
  • 5,056
  • 9
  • 62
  • 136
  • 1
    It looks the link you provided is from Google Translate (a free multilingual machine translation service) [https://en.wikipedia.org/wiki/Google_Translate] instead of Cloud Translation API (provides a simple programmatic interface for translating an arbitrary string into any supported language using state-of-the-art Neural Machine Translation) [https://cloud.google.com/translate/] – JL-HaiNan Apr 20 '17 at 17:59
  • So actually these are two different services that you're comparing. – JL-HaiNan Apr 20 '17 at 19:00
  • What is so special in Google from Somalia? – Daniil Iaitskov Jul 08 '18 at 18:52
  • 2
    @Anatoly The above mentioned free API for translation is actually not free. It will result in 503 after some fast and repetitive usage. – Harsh Sharma Mar 16 '19 at 16:48

2 Answers2

5

Of course it is free and you can implement it (I included an example below). However, DO NOT USE IT because after a while Google can detect suspicious traffic –it happened to me, sadly- so you will receive an error message. I'm not sure how long can you use it until they can detect your activity so my advice for you is to test extensively your app with the "free service" and if you see some troubles perhaps you should buy the service or look for another API. https://api.mymemory.translated.net is a free but limited alternative.

In iOS Swift 4 you can implement the free service by using the following function:

func translate(str: String, lang1: String, lang2: String) {

    let escapedStr = str.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
    let lastPart = lang1 + "&tl=" + lang2 + "&dt=t&dt=t&q=" + escapedStr!
    let urlStr: String = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + lastPart
    let url = URL(string: urlStr)

    let task = URLSession.shared.downloadTask(with: url!) { localURL, urlResponse, error in
        if let localURL = localURL {
            if let string = try? String(contentsOf: localURL) {
                let index = string.firstIndex(of: "\"")
                let index2 = string.index(after: index!)
                let subst = string.substring(from: index2)
                let indexf = subst.firstIndex(of: "\"")
                let result = subst.substring(to: indexf!)
                DispatchQueue.main.async {
                    if flag1country != flag2country {
                        self.texto.text = result
                    }
                }
            }
        }
    }
    task.resume()
}

(Perhaps this is not the best implementation, but it works).

  • 1
    It was implemented in an iOS app. I was testing the app without my computer, so I'm not sure. However, my application made too many requests in a short period of time, more or less 7 requests/second. In about five minutes the application was gone. Nevertheless, I will continue testing and after that I'll inform my findings. The error message –quite long– basically said that I did several requests in a short period. However, it seems that Google do not allow that kind of usage for the service, according with their terms of usage. – Javier Aguilar Dec 31 '18 at 02:20
  • 1
    Seems that you can avoid the detection by using the API slowly, but not sure that it's legal that way. – Javier Aguilar Dec 31 '18 at 02:24
1

It looks the link you provided is from Google Translate (not an API but a free multilingual machine translation service) instead of Cloud Translation API, which provides a simple programmatic interface for translating an arbitrary string into any supported language using state-of-the-art Neural Machine Translation; so they are not the way you think.

JL-HaiNan
  • 1,004
  • 9
  • 20
  • Thank you for your response? But can I use this *free service* and where can I read a little more about it? – Anatoly Apr 21 '17 at 20:18
  • I just seen that some Chrome extensions which available in Chrome app store use this service. – Anatoly Apr 21 '17 at 20:19
  • 1
    Hi, you can read more details regarding Google Translate at https://en.wikipedia.org/wiki/Google_Translate and https://support.google.com/translate/?hl=en#topic=7011755; you can definitely use this free service. – JL-HaiNan Apr 24 '17 at 15:54