Esempio n. 1
0
        void OnLanguageTranslated(Dictionary <string, TranslationQuery> requests, 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();
            StopConnectionWWW();

            if (!string.IsNullOrEmpty(Error))
            {
                ShowError(Error);
                return;
            }

            if (requests.Values.Count == 0)
            {
                return;
            }

            var langCode = requests.Values.First().TargetLanguagesCode [0];
            //langCode = GoogleLanguages.GetGoogleLanguageCode(langCode);
            int langIndex = mLanguageSource.GetLanguageIndexFromCode(langCode, false);

            //if (langIndex >= 0)
            {
                foreach (var term in mTranslationTerms)
                {
                    var termData = mLanguageSource.GetTermData(term, false);
                    if (termData == null)
                    {
                        continue;
                    }
                    if (termData.TermType != eTermType.Text)
                    {
                        continue;
                    }
                    //if (termData.Languages.Length <= langIndex)
                    //  continue;

                    string sourceCode, sourceText;
                    FindTranslationSource(LanguageSourceData.GetKeyFromFullTerm(termData.Term), termData, langCode, null, out sourceText, out sourceCode);

                    string result = GoogleTranslation.RebuildTranslation(sourceText, mTranslationRequests, langCode);               // gets the result from google and rebuilds the text from multiple queries if its is plurals

                    termData.Languages[langIndex] = result;
                }
            }

            mTranslationTerms.Clear();
            mTranslationRequests.Clear();
            StopConnectionWWW();
        }