Giter VIP home page Giter VIP logo

free-google-translate's Introduction

Free Google Translator

GitHub license Documentation Status made-with-python made-with-javascript Ask Me Anything !

Free Google Translate is a tool for google free translation API, the main idea of the repo is coming from the web https://translate.google.cn translation, we use a hacking way to access the web translation api for translating text.

The Do's and Don'ts

  • 1.You will get 429 Too many requests error if you request so many times simultaneously
    • Suggested Solution: To avoid requests in just one IP address, you can put the requesting code in every client (app on device), then it will bypass the IP restriction
  • 2.The api service is unavailable if you send large amount of requests at the same time.

For Python Example

text = "Hello world"
GoogleTrans().query(text, lang_to='zh-CN') 

You pass a string of plain text with target language code, then you will get the translated text after requested. the request api will recognize the source language of the text automatically for you.

The output will be:

Before translating: "Hello world" with target lange code en
After translating: "你好,世界"


For Objective-C Example on iOS

NSString *content = @"Hello world";
NSString *targetLanguage = @"zh-CN";
YLGoogleTranslate *googleTrans = [[YLGoogleTranslate alloc] init];
[googleTrans translateWithText:content targetLanguageCode:targetLanguage completion:^(NSString * _Nullable originalText, NSString * _Nullable originalLanguageCode, NSString * _Nullable translatedText, NSString * _Nullable targetLanguageCode, NSString * _Nullable error) {
    if ([error length] > 0) {
        NSLog(@"The Request returned error! Error Message: %@", error); 
    } else {
        NSLog(@"The Request returned success!!!!!!");
    }
}];

The response data is as same as aforementioned python code.







free-google-translate

Free Google Translator API 免费的Google翻译,其中的破解思路主要来源于将 https://translate.google.cn 的web访问方式模拟成全部代码的形式来控制api的访问

注意事项

  • 1.大量的相同IP请求会导致Google翻译接口返回 429 Too many requests
    • 建议处理方案:每一个app客户端自己去请求此接口,就可以避免只有一个IP的服务器去请求
  • 2.大量的请求也会使此接口的服务不可用

Python使用

text = "Hello world"
GoogleTrans().query(text, lang_to='zh-CN') 

传入一段待翻译的文本,和目标翻译语言code,然后你就会得到翻译结果,该接口会自动识别输入的语言code

输出结果是:

翻译前:Hello world,翻译前code:en
翻译后:你好,世界, 翻译后code:zh-CN


iOS Objective-C使用

NSString *content = @"Hello world";
NSString *targetLanguage = @"zh-CN";
YLGoogleTranslate *googleTrans = [[YLGoogleTranslate alloc] init];
[googleTrans translateWithText:content targetLanguageCode:targetLanguage completion:^(NSString * _Nullable originalText, NSString * _Nullable originalLanguageCode, NSString * _Nullable translatedText, NSString * _Nullable targetLanguageCode, NSString * _Nullable error) {
    if ([error length] > 0) {
        NSLog(@"调用Google翻译接口返回错误:%@ ", error); 
    } else {
        NSLog(@"调用Google翻译接口返回成功!");
    }
}];

传入一段待翻译的文本,和目标翻译语言code,然后你就会得到翻译结果,该接口会自动识别输入的语言code

free-google-translate's People

Contributors

m-bonjour avatar qiangzhang2021 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.