void OnLanguageTranslated(string Result, string Error)
        {
            //Debug.Log (Result);
            if (!string.IsNullOrEmpty(Error) /* || !Result.Contains("<i2>")*/)
            {
                ShowError("Unable to access Google or not valid request");
                return;
            }

            ClearErrors();
            Error = GoogleTranslation.ParseTranslationResult(Result, mTranslationRequests);
            if (!string.IsNullOrEmpty(Error))
            {
                ShowError(Error);
                return;
            }


            foreach (var request in mTranslationRequests)
            {
                if (request.Results == null)                    // Handle cases where not all translations were valid
                {
                    continue;
                }

                var termData = mLanguageSource.GetTermData(request.Term);
                if (termData == null)
                {
                    continue;
                }

                string lastCode    = "";
                int    lastcodeIdx = 0;

                for (int i = 0; i < request.Results.Length; ++i)
                {
                    //--[ most of the time is a single code, so this works as a cache
                    if (lastCode != request.TargetLanguagesCode[i])
                    {
                        lastCode    = request.TargetLanguagesCode[i];
                        lastcodeIdx = mLanguageSource.GetLanguageIndexFromCode(lastCode);
                    }

                    if (GUI_SelectedInputType == 0)
                    {
                        termData.Languages[lastcodeIdx] = request.Results[i];
                    }
                    else
                    {
                        termData.Languages_Touch[lastcodeIdx] = request.Results[i];
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void ProcessResult(byte[] bytes, string errorMsg)
 {
     if (!string.IsNullOrEmpty(errorMsg))
     {
         // check for
         //if (errorMsg.Contains("rewind"))  // "necessary data rewind wasn't possible"
         mJobState = eJobState.Failed;
     }
     else
     {
         var wwwText = Encoding.UTF8.GetString(bytes, 0, bytes.Length); //www.text
         errorMsg = GoogleTranslation.ParseTranslationResult(wwwText, _requests);
         if (_OnTranslationReady != null)
         {
             _OnTranslationReady(_requests, errorMsg);
         }
         mJobState = eJobState.Succeeded;
     }
 }
Exemplo n.º 3
0
        public void ProcessResult(byte[] bytes, string errorMsg)
        {
            if (string.IsNullOrEmpty(errorMsg))
            {
                var wwwText = Encoding.UTF8.GetString(bytes, 0, bytes.Length); //www.text
                errorMsg = GoogleTranslation.ParseTranslationResult(wwwText, _requests);

                if (string.IsNullOrEmpty(errorMsg))
                {
                    if (_OnTranslationReady != null)
                    {
                        _OnTranslationReady(_requests, null);
                    }
                    return;
                }
            }

            mJobState     = eJobState.Failed;
            mErrorMessage = errorMsg;
        }
Exemplo n.º 4
0
        void OnLanguageTranslated(string Result, string Error)
        {
            //Debug.Log (Result);

            if (Result.Contains("Service invoked too many times"))
            {
                TimeStartTranslation      = EditorApplication.timeSinceStartup + 1;
                EditorApplication.update += DelayedStartTranslation;
                mConnection_Text          = "Translating (" + mTranslationRequests.Count + ")";
                return;
            }

            if (!string.IsNullOrEmpty(Error))            /* || !Result.Contains("<i2>")*/
            {
                Debug.LogError("WEB ERROR: " + Error);
                ShowError("Unable to access Google or not valid request");
                return;
            }

            ClearErrors();
            Error = GoogleTranslation.ParseTranslationResult(Result, mTranslationRequests);
            if (!string.IsNullOrEmpty(Error))
            {
                ShowError(Error);
                return;
            }


            foreach (var request in mTranslationRequests)
            {
                if (request.Results == null)                    // Handle cases where not all translations were valid
                {
                    continue;
                }

                var termData = mLanguageSource.GetTermData(request.Term);
                if (termData == null)
                {
                    continue;
                }

                string lastCode    = "";
                int    lastcodeIdx = 0;

                for (int i = 0; i < request.Results.Length; ++i)
                {
                    //--[ most of the time is a single code, so this works as a cache
                    if (lastCode != request.TargetLanguagesCode[i])
                    {
                        lastCode    = request.TargetLanguagesCode[i];
                        lastcodeIdx = mLanguageSource.GetLanguageIndexFromCode(lastCode);
                    }

                    if (GUI_SelectedInputType == 0)
                    {
                        termData.Languages[lastcodeIdx] = request.Results[i];
                    }
                    else
                    {
                        termData.Languages_Touch[lastcodeIdx] = request.Results[i];
                    }
                }
            }
            mTranslationRequests.RemoveAll(x => x.Results != null && x.Results.Length > 0);

            if (mTranslationRequests.Count > 0)
            {
                TimeStartTranslation      = EditorApplication.timeSinceStartup + 1;
                EditorApplication.update += DelayedStartTranslation;
                mConnection_Text          = "Translating (" + mTranslationRequests.Count + ")";
            }
        }