Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:06:22+00:00 2026-06-02T21:06:22+00:00

The following is my code for using Google Translate. I have one dll I

  • 0

The following is my code for using Google Translate. I have one dll I added as a reference: Google.Apis.Translate.V2
I also bought Google Translate API key.

I have 5 errors since I don’t know what dll I need more: These objects do not exist missing namespace: DataContractJsonSerializer , TranslationRootObject , TranslationRootObject

What dll reference do I need for these namespaces?

This is my code, without my API key:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Web;

namespace Google_Translate
{
    public partial class Form1 : Form
    {
        static string apiKey = "";

        static string texttotranslate = "hello world";
        string text;
        static String apiUrl = "https://www.googleapis.com/language/translate/v2?key={0}&source={1}&target={2}&q={3}";
            static String url = String.Format(apiUrl, apiKey, "en", "ge", texttotranslate);
            Stream outputStream = null;

        byte[] bytes = Encoding.ASCII.GetBytes(url);

        // create the http web request
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);



        public Form1()
        {
            InitializeComponent();

            webRequest.KeepAlive = true;
            webRequest.Method = "POST";
            // Overrride the GET method as documented on Google's docu.
            webRequest.Headers.Add("X-HTTP-Method-Override: GET");
            webRequest.ContentType = "application/x-www-form-urlencoded";
            // send POST
            try
            {
                webRequest.ContentLength = bytes.Length;
                outputStream = webRequest.GetRequestStream();
                outputStream.Write(bytes, 0, bytes.Length);
                outputStream.Close();
            }
            catch (HttpListenerException e)
            {
                /*...*/
            }

            translate();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private string translate()
        {
             try
        {
            // get the response
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
            if (webResponse.StatusCode == HttpStatusCode.OK && webRequest != null)
            {
                // read response stream 
                using (StreamReader sr = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
                {
                    string lista = sr.ReadToEnd();

                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TranslationRootObject));
                    MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(lista));
                    TranslationRootObject tRootObject = (TranslationRootObject)serializer.ReadObject(stream);
                    string previousTranslation = string.Empty;

                    //deserialize
                    for (int i = 0; i < tRootObject.Data.Detections.Count; i++)
                    {
                        string translatedText = tRootObject.Data.Detections[i].TranslatedText.ToString();
                        if (i == 0)
                        {
                            text = translatedText;
                        }
                        else
                        {
                            if (!text.Contains(translatedText))
                            {
                                text = text + " " + translatedText;
                            }
                        }
                    }
                    return text;
                }
            }
        }
        catch (HttpListenerException e)
        {
            /*...*/
        }

        return text;



        }
    }
}

Can someone fix my code or tell me whats wrong please ?

What I need is to translate 29-33kb text file size and I wonder if it’s possible to translate it as fast as it does online when using the Google Translate site.

I also found this link Google Translate V2 cannot hanlde large text translations from C# which someone say the translation can’t translate big files so I wonder if 29-33kb files are counting as big? If so maybe someone can take a look at the link and fix my code according to the answer in the link I tried a lot now and didn’t understand it really. But first I need to find why my original code here doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:06:26+00:00Added an answer on June 2, 2026 at 9:06 pm

    In your project, add a reference to this assembly:

    http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx

    There may be others you need, I just looked up this one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code( to draw a map using google map API V3):
I'm using jQuery version 1.7.1 from Google CDN and have the following code: $(menuInstance).delay(2000).removeClass('loading').html(ul);
I am using google admob in my application. I have the following code: GADRequest
The following code is a part of using google api access. After connectDb(), there
I have the following C++ code: #include <iostream> #include <google/dense_hash_map> #include <string.h> using google::dense_hash_map;
I'm using Google Chrome 16.0.912.63 and have the following code: __defineGetter__('x', function(){ console.log('In Getter:
I'm following the barcode tutorial for this site: http://brismith66.blogspot.com/2010_07_01_archive.html using the google code: http://code.google.com/p/wsdl2objc/
I am using 'git' to checkout chromium code by following this document: http://code.google.com/p/chromium/wiki/UsingGit And
I have the following code: using (var fact = new WebChannelFactory<IService<Message>>(binding, commsSettings.MessageEndPoint())) { using
I have the following code: using System; using System.Linq; using System.Linq.Expressions; public class Program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.