コード例 #1
0
        static void Translate(string Key, ref TermData termdata, ref string sTarget, string TargetLanguageCode)
        {
                        #if UNITY_WEBPLAYER
            ShowError("Contacting google translation is not yet supported on WebPlayer");
                        #else
            // Translate first language that has something
            // If no language found, translation will fallback to autodetect language from key
            string SourceCode = "auto";
            string text       = Key;

            string[] lans = (GUI_SelectedInputType == 0 ? termdata.Languages : termdata.Languages_Touch);
            for (int i = 0, imax = lans.Length; i < imax; ++i)
            {
                if (!string.IsNullOrEmpty(lans[i]))
                {
                    text = lans[i];
                    if (mLanguageSource.mLanguages[i].Code != TargetLanguageCode)
                    {
                        SourceCode = mLanguageSource.mLanguages[i].Code;
                        break;
                    }
                }
            }

            sTarget = GoogleTranslation.ForceTranslate(text, SourceCode, TargetLanguageCode);
                        #endif
        }
コード例 #2
0
        static void Translate(string Key, ref TermData termdata, ref string sTarget, string TargetLanguageCode)
        {
                        #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);
            sTarget = GoogleTranslation.ForceTranslate(sourceText, sourceCode, TargetLanguageCode);
                        #endif
        }
コード例 #3
0
        public void ExampleMultiTranslations_Blocking()
        {
            // This shows how to ask for many translations
            var dict = new System.Collections.Generic.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);

            if (!GoogleTranslation.ForceTranslate(dict))
            {
                return;
            }

            Debug.Log(GoogleTranslation.GetQueryResult("This is an example", "en", dict));
            Debug.Log(GoogleTranslation.GetQueryResult("This is an example", "zh", dict));
            Debug.Log(GoogleTranslation.GetQueryResult("This is an example", "", dict)); // This returns ANY translation of that text (in this case, the first one 'en')
            Debug.Log(dict["Hola"].Results[0]);                                          // example of getting the translation directly from the Results
        }