public void CreateJob() { var mygengo = new MyGengoClient(ApiKeys.PublicKey, ApiKeys.PrivateKey, useSandbox: true); var job = new TranslationJob("My slug", "trololololol", "en", "ja", Tier.Standard); XDocument response = mygengo.PostTranslationJob(job); // response.Root.Element("response") is your ideal response! }
public void DetermineTranslationCost() { var mygengo = new MyGengoClient(ApiKeys.PublicKey, ApiKeys.PrivateKey, useSandbox: true); var job = new TranslationJob("Slug", "Mmmhmm, yes, yes, quite right", "en", "ja", Tier.Standard); XDocument response = mygengo.DetermineTranslationCost(job); // response.Root.Element("response") is your ideal response! }
public void TestJobCreation() { var myGengo = new MyGengoClient(ApiKeys.PublicKey, ApiKeys.PrivateKey, useSandbox: true); var rnd = new Random(); string text = string.Format("Test{0}ing myGe{1}ngo A{2}PI li{3}brary calls.", rnd.Next(1, 226), rnd.Next(1, 226), rnd.Next(1, 226), rnd.Next(1, 226)); var job = new TranslationJob(text, "en", "ja", Tier.Standard); XDocument response = myGengo.PostTranslationJob(job); Assert.AreEqual("ok", response.Root.Element("opstat").Value); Assert.IsNotNull(response.Root.Element("response").Element("job").Element("job_id").Value); }
public void TestMultipleJobCreation() { var myGengo = new MyGengoClient(ApiKeys.PublicKey, ApiKeys.PrivateKey, useSandbox: true); var rnd = new Random(); var jobs = new TranslationJob[3]; for (int i = 0; i < 3; i++) { string text = string.Format("Test{0}ing myGe{1}ngo A{2}PI li{3}brary calls.", rnd.Next(1, 226), rnd.Next(1, 226), rnd.Next(1, 226), rnd.Next(1, 226)); jobs[i] = new TranslationJob(text, "en", "ja", Tier.Standard); } XDocument response = myGengo.PostTranslationJobs(jobs, shouldProcess: false); Assert.AreEqual("ok", response.Root.Element("opstat").Value); Assert.AreEqual(3, response.Root.Descendants("item").Count()); }
public void CreateJob() { var mygengo = new MyGengoClient(ApiKeys.PublicKey, ApiKeys.PrivateKey, useSandbox: true); var rnd = new Random(); var jobs = new TranslationJob[3]; for (int i = 0; i < 3; i++) { // The same text is used here for slug and translation; they are fine to be different. string text = string.Format("Test{0}ing myGe{1}ngo A{2}PI li{3}brary calls.", rnd.Next(1, 226), rnd.Next(1, 226), rnd.Next(1, 226), rnd.Next(1, 226)); jobs[i] = new TranslationJob(text, text, "en", "ja", Tier.Standard); } /** * Can pass shouldProcess and/or processAsGroup; former pays immediately, latter * keeps them all under one translator (advisable for context). */ XDocument response = myGengo.PostTranslationJobs(jobs, processAsGroup: true, shouldProcess: false); // response.Root.Element("response") is your ideal response! }
public XDocument PostTranslationJobs(TranslationJob[] jobs, bool processAsGroup=false, bool shouldProcess=true) { try { string url = baseUrl + "translate/jobs/"; var data = new Dictionary<string, object>(); data.Add("jobs", jobs.Select(x => x.ToDictionary()).ToArray()); data.Add("as_group", processAsGroup ? 1 : 0); data.Add("process", shouldProcess ? 1 : 0); return api.Call(url, HttpMethod.Post, data, requiresAuthentication: true); } catch (MyGengoException x) { throw x; } catch (Exception x) { throw new MyGengoException(x.Message, x); } }
public XDocument PostTranslationJob(TranslationJob job) { try { string url = baseUrl + "translate/job/"; var data = new Dictionary<string, object>(); data.Add("job", job.ToDictionary()); return api.Call(url, HttpMethod.Post, data, requiresAuthentication: true); } catch (MyGengoException x) { throw x; } catch (Exception x) { throw new MyGengoException(x.Message, x); } }