谷歌翻译与c

发布于 2024-10-10 09:04:11 字数 37 浏览 9 评论 0原文

任何人都知道如何使用 c 来使用 Google 翻译 API

Any one know how to use the Google translate API using c

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素食主义者 2024-10-17 09:04:11

此处描述了一个可用的 REST API。您应该能够从 C 轻松访问它。

There is a REST API available described here. You should be able to access that easily enough from C.

苏大泽ㄣ 2024-10-17 09:04:11

感谢 pwc,我使用了他的资源并使用管道创建了它,这是它的源代码

  char  chrptr_GoogleResponse [0x1000];
  char* chrptr_pos2 = NULL;
  char* translate_text = search_str;           
  char* lang_pairs = "&langpair=es%7Cen'";     // language pairs
  bool boNoError = true;

    strcpy(chrarray_GoogleCommand, "curl -s -e http://www.my-ajax-site.com \
            'https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=");

    strcat(chrarray_GoogleCommand, translate_text);
    strcat(chrarray_GoogleCommand, lang_pairs);

    popen(chrarray_GoogleCommand, "r");

    FILE* fileptrFile = popen(chrarray_GoogleCommand, "r");

 if (fileptrFile == NULL)
    {
        printf("Error on opening pipe\n.");
        exit(EXIT_FAILURE);
    }

 while ( !feof (fileptrFile) )
    {
        fgets (chrptr_GoogleResponse , 0x1000 , fileptrFile) ;

        chrptr_pos1 = strstr(chrptr_GoogleResponse, "{\"translatedText\":\"") ;
        if ( chrptr_pos1 )
        {
            chrptr_pos1 = chrptr_pos1 + strlen("{\"translatedText\":\"") ;
            chrptr_pos2 = strstr(chrptr_GoogleResponse, "\"}, \"responseDetails\": null, \"responseStatus\": 200}") ;
            if ( chrptr_pos2 )
            {
                memcpy(chrptr_temp, chrptr_pos1, chrptr_pos2 - chrptr_pos1);
                memset((void*) ((unsigned long) chrptr_temp + (unsigned long) chrptr_pos2 - (unsigned long) chrptr_pos1), 0, 1);
            }
            else
                boNoError = false ;
        }
        else
            boNoError = false ;

        if (feof (fileptrFile))
            break;
    }
    pclose(fileptrFile);

    if (boNoError)
        strcpy(search_str, chrptr_temp); //copy translated text.

Thanks to pwc i used his resource and created it with pipes and here is the source code for it

  char  chrptr_GoogleResponse [0x1000];
  char* chrptr_pos2 = NULL;
  char* translate_text = search_str;           
  char* lang_pairs = "&langpair=es%7Cen'";     // language pairs
  bool boNoError = true;

    strcpy(chrarray_GoogleCommand, "curl -s -e http://www.my-ajax-site.com \
            'https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=");

    strcat(chrarray_GoogleCommand, translate_text);
    strcat(chrarray_GoogleCommand, lang_pairs);

    popen(chrarray_GoogleCommand, "r");

    FILE* fileptrFile = popen(chrarray_GoogleCommand, "r");

 if (fileptrFile == NULL)
    {
        printf("Error on opening pipe\n.");
        exit(EXIT_FAILURE);
    }

 while ( !feof (fileptrFile) )
    {
        fgets (chrptr_GoogleResponse , 0x1000 , fileptrFile) ;

        chrptr_pos1 = strstr(chrptr_GoogleResponse, "{\"translatedText\":\"") ;
        if ( chrptr_pos1 )
        {
            chrptr_pos1 = chrptr_pos1 + strlen("{\"translatedText\":\"") ;
            chrptr_pos2 = strstr(chrptr_GoogleResponse, "\"}, \"responseDetails\": null, \"responseStatus\": 200}") ;
            if ( chrptr_pos2 )
            {
                memcpy(chrptr_temp, chrptr_pos1, chrptr_pos2 - chrptr_pos1);
                memset((void*) ((unsigned long) chrptr_temp + (unsigned long) chrptr_pos2 - (unsigned long) chrptr_pos1), 0, 1);
            }
            else
                boNoError = false ;
        }
        else
            boNoError = false ;

        if (feof (fileptrFile))
            break;
    }
    pclose(fileptrFile);

    if (boNoError)
        strcpy(search_str, chrptr_temp); //copy translated text.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文