Beispiel #1
0
        // Query google for the translation and waits until google returns
        // On some Unity versions (e.g. 2017.1f1) unity doesn't handle well waiting for WWW in the main thread, so this call can fail
        // In those cases, its advisable to use the Async version  (GoogleTranslation.Translate(....))
        public static string ForceTranslate(string text, string LanguageCodeFrom, string LanguageCodeTo)
        {
            TranslationDictionary dict = new TranslationDictionary();

            AddQuery(text, LanguageCodeFrom, LanguageCodeTo, dict);

            var job = new TranslationJob_Main(dict, null);

            while (true)
            {
                var state = job.GetState();
                if (state == TranslationJob.eJobState.Running)
                {
                    continue;
                }

                if (state == TranslationJob.eJobState.Failed)
                {
                    return(null);
                }

                //TranslationJob.eJobState.Succeeded
                return(GetQueryResult(text, "", dict));
            }
        }
Beispiel #2
0
        public static bool ForceTranslate(TranslationDictionary requests, bool usePOST = true)
        {
            var job = new TranslationJob_Main(requests, null);

            while (true)
            {
                var state = job.GetState();
                if (state == TranslationJob.eJobState.Running)
                {
                    continue;
                }

                if (state == TranslationJob.eJobState.Failed)
                {
                    return(false);
                }

                //TranslationJob.eJobState.Succeeded
                return(true);
            }
        }