Search code examples
google-apigoogle-translategoogle-translation-api

Google Translate API (paid) vs Google Translate API (free)?


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?


Solution

  • 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).