예제 #1
0
        void StartTranslating(string fromCode, string toCode)
        {
            IsTranslating = true;

            // fromCode could be "auto" to autodetect the language
            GoogleTranslation.Translate(OriginalText, fromCode, toCode, OnTranslationReady);
        }
예제 #2
0
        void TranslateAllToLanguage(string lanName)
        {
            if (!GoogleTranslation.CanTranslate())
            {
                ShowError("WebService is not set correctly or needs to be reinstalled");
                return;
            }
            ClearErrors();
            int    LanIndex   = mLanguageSource.GetLanguageIndex(lanName);
            string code       = mLanguageSource.mLanguages [LanIndex].Code;
            string googleCode = GoogleLanguages.GetGoogleLanguageCode(code);

            if (string.IsNullOrEmpty(googleCode))
            {
                ShowError("Language '" + code + "' is not supported by google translate");
                return;
            }
            googleCode = code;

            mTranslationTerms.Clear();
            mTranslationRequests.Clear();
            foreach (var termData in mLanguageSource.mTerms)
            {
                if (termData.TermType != eTermType.Text)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(termData.Languages[LanIndex]))
                {
                    continue;
                }

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

                mTranslationTerms.Add(termData.Term);

                GoogleTranslation.CreateQueries(sourceText, sourceCode, googleCode, mTranslationRequests);                   // can split plurals into several queries
            }

            if (mTranslationRequests.Count == 0)
            {
                StopConnectionWWW();
                return;
            }

            mConnection_WWW  = null;
            mConnection_Text = "Translating"; if (mTranslationRequests.Count > 1)
            {
                mConnection_Text += " (" + mTranslationRequests.Count + ")";
            }
            mConnection_Callback = null;
            //EditorApplication.update += CheckForConnection;

            GoogleTranslation.Translate(mTranslationRequests, OnLanguageTranslated);
        }
예제 #3
0
        public void StartTranslating(string fromCode, string toCode)
        {
            IsTranslating = true;

            // fromCode could be "auto" to autodetect the language
            GoogleTranslation.Translate(OriginalText, fromCode, toCode, OnTranslationReady);

            // can also use the ForceTranslate version: (it will block the main thread until the translation is returned)
            //var translation = GoogleTranslation.ForceTranslate(OriginalText, fromCode, toCode);
            //Debug.Log(translation);
        }
예제 #4
0
        public void ExampleMultiTranslations_Async()
        {
            IsTranslating = true;

            // This shows how to ask for many translations
            var dict = new Dictionary <string, TranslationQuery>();

            GoogleTranslation.AddQuery("This is an example", "en", "es", dict);
            GoogleTranslation.AddQuery("This is an example", "auto", "zh", dict);
            GoogleTranslation.AddQuery("Hola", "es", "en", dict);

            GoogleTranslation.Translate(dict, OnMultitranslationReady);
        }
        static void Translate(string Key, ref TermData termdata, string TargetLanguageCode, Action <string, string> onTranslated)
        {
                        #if UNITY_WEBPLAYER
            ShowError("Contacting google translation is not yet supported on WebPlayer");
                        #else
            if (!GoogleTranslation.CanTranslate())
            {
                ShowError("WebService is not set correctly or needs to be reinstalled");
                return;
            }

            // Translate first language that has something
            // If no language found, translation will fallback to autodetect language from key

            string sourceCode, sourceText;
            FindTranslationSource(Key, termdata, TargetLanguageCode, out sourceText, out sourceCode);
            GoogleTranslation.Translate(sourceText, sourceCode, TargetLanguageCode, onTranslated);
                        #endif
        }
예제 #6
0
 private void StartTranslating(string fromCode, string toCode)
 {
     IsTranslating = true;
     GoogleTranslation.Translate(OriginalText, fromCode, toCode, OnTranslationReady);
 }