Exemplo n.º 1
0
        static void TranslateLanguage(string Key, TermData termdata, Localize localizeCmp, LanguageSourceData source)
        {
            ClearErrors();
            string mainText = localizeCmp == null?LanguageSourceData.GetKeyFromFullTerm(Key) : localizeCmp.GetMainTargetsText();

            for (int i = 0; i < source.mLanguages.Count; ++i)
            {
                if (source.mLanguages[i].IsEnabled() && string.IsNullOrEmpty(termdata.Languages[i]))
                {
                    var langIdx  = i;
                    var term     = termdata;
                    var i2source = source;
                    Translate(mainText, ref termdata, source.mLanguages[i].Code,
                              (translation, error) =>
                    {
                        if (error != null)
                        {
                            ShowError(error);
                        }
                        else
                        if (translation != null)
                        {
                            term.Languages[langIdx] = translation;             //SetTranslation(langIdx, translation);
                            i2source.Editor_SetDirty();
                        }
                    }, null);
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public bool IsTerm(string name, bool allowCategoryMistmatch)
        {
            if (!allowCategoryMistmatch)
            {
                return(name == Term);
            }

            return(name == LanguageSourceData.GetKeyFromFullTerm(Term));
        }
Exemplo n.º 4
0
        List <string> ScriptTool_GetSelectedTermsInCategory(string Category)
        {
            List <string> list = new List <string>();

            foreach (string FullKey in mSelectedKeys)
            {
                string categ = LanguageSourceData.GetCategoryFromFullTerm(FullKey);
                if (categ == Category && ShouldShowTerm(FullKey))
                {
                    list.Add(LanguageSourceData.GetKeyFromFullTerm(FullKey));
                }
            }

            return(list);
        }
Exemplo n.º 5
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();
        }