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

天涯浪子 提交于 2019-12-21 02:51:01

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/43155233/google-translate-api-paid-vs-google-translate-api-free

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!