123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- namespace I2.Loc
- {
- public class TranslationJob_POST : TranslationJob_WWW
- {
- public TranslationJob_POST(Dictionary<string, TranslationQuery> requests, Action<Dictionary<string, TranslationQuery>, string> OnTranslationReady)
- {
- this._requests = requests;
- this._OnTranslationReady = OnTranslationReady;
- List<string> list = GoogleTranslation.ConvertTranslationRequest(requests, false);
- WWWForm wwwform = new WWWForm();
- wwwform.AddField("action", "Translate");
- wwwform.AddField("list", list[0]);
- this.www = new WWW(LocalizationManager.GetWebServiceURL(null), wwwform);
- }
- public override TranslationJob.eJobState GetState()
- {
- if (this.www != null && this.www.isDone)
- {
- this.ProcessResult(this.www.bytes, this.www.error);
- this.www.Dispose();
- this.www = null;
- }
- return this.mJobState;
- }
- public void ProcessResult(byte[] bytes, string errorMsg)
- {
- if (!string.IsNullOrEmpty(errorMsg))
- {
- this.mJobState = TranslationJob.eJobState.Failed;
- }
- else
- {
- string @string = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
- errorMsg = GoogleTranslation.ParseTranslationResult(@string, this._requests);
- if (this._OnTranslationReady != null)
- {
- this._OnTranslationReady(this._requests, errorMsg);
- }
- this.mJobState = TranslationJob.eJobState.Succeeded;
- }
- }
- private Dictionary<string, TranslationQuery> _requests;
- private Action<Dictionary<string, TranslationQuery>, string> _OnTranslationReady;
- }
- }
|