public void Initialize() { Settings.Configure(); HooksSetup.InstallHooks(Any_TextChanged); AutoTranslateClient.Configure(); LoadTranslations(); // start a thread that will periodically removed unused references var t1 = new Thread(RemovedUnusedReferences); t1.IsBackground = true; t1.Start(); // start a thread that will periodically save new translations var t2 = new Thread(SaveTranslationsLoop); t2.IsBackground = true; t2.Start(); // subscribe to text changes UGUIHooks.TextAwakened += UguiTextEvents_OnTextAwaken; UGUIHooks.TextChanged += UguiTextEvents_OnTextChanged; IMGUIHooks.TextChanged += IMGUITextEvents_GUIContentChanged; NGUIHooks.TextChanged += NGUITextEvents_TextChanged; TextMeshProHooks.TextAwakened += TextMeshProHooks_OnTextAwaken; TextMeshProHooks.TextChanged += TextMeshProHooks_OnTextChanged; }
public void Initialize() { Current = this; Settings.Configure(); HooksSetup.InstallHooks(Override_TextChanged); AutoTranslateClient.Configure(); _symbolCheck = TextHelper.GetSymbolCheck(Settings.FromLanguage); LoadTranslations(); // start a thread that will periodically removed unused references var t1 = new Thread(RemovedUnusedReferences); t1.IsBackground = true; t1.Start(); // start a thread that will periodically save new translations var t2 = new Thread(SaveTranslationsLoop); t2.IsBackground = true; t2.Start(); }
private void KickoffTranslations() { while (AutoTranslateClient.HasAvailableClients && _unstartedJobs.Count > 0) { var job = _unstartedJobs[_unstartedJobs.Count - 1]; _unstartedJobs.RemoveAt(_unstartedJobs.Count - 1); // lets see if the text should still be translated before kicking anything off if (job.UI != null) { var text = GetText(job.UI).Trim(); if (text != job.UntranslatedText) { continue; // just ignore this UI component, as the text has already changed anyway (maybe from game, maybe from other plugin) } } //StartCoroutine( AutoTranslateClient.TranslateByWWW( job.UntranslatedText.ChangeToSingleLineForDialogue(), Settings.FromLanguage, Settings.Language, translatedText => //{ // _consecutiveErrors = 0; // job.TranslatedText = translatedText; // if( !string.IsNullOrEmpty( translatedText ) ) // { // lock( _writeToFileSync ) // { // _newTranslations[ job.UntranslatedText ] = translatedText; // } // } // _completedJobs.Add( job ); //}, //() => //{ // _consecutiveErrors++; //} ) ); StartCoroutine(AutoTranslateClient.TranslateByWWW(job.UntranslatedText.ChangeToSingleLineForDialogue(), Settings.FromLanguage, Settings.Language, translatedText => { _consecutiveErrors = 0; job.TranslatedText = translatedText; if (!string.IsNullOrEmpty(translatedText)) { lock ( _writeToFileSync ) { _newTranslations[job.UntranslatedText] = translatedText; } } _completedJobs.Add(job); }, () => { _consecutiveErrors++; })); } }
private void KickoffTranslations() { foreach (var kvp in _unstartedJobs) { if (!AutoTranslateClient.HasAvailableClients) { break; } var key = kvp.Key; var job = kvp.Value; _kickedOff.Add(key); // lets see if the text should still be translated before kicking anything off if (!job.AnyComponentsStillHasOriginalUntranslatedText()) { continue; } StartCoroutine(AutoTranslateClient.TranslateByWWW(job.Keys.ForcedRelevantKey, Settings.FromLanguage, Settings.Language, translatedText => { _consecutiveErrors = 0; if (Settings.ForceSplitTextAfterCharacters > 0) { translatedText = translatedText.SplitToLines(Settings.ForceSplitTextAfterCharacters, '\n', ' ', ' '); } job.TranslatedText = translatedText; if (!string.IsNullOrEmpty(translatedText)) { QueueNewTranslationForDisk(job.Keys, translatedText); _completedJobs.Add(job); } }, () => { _consecutiveErrors++; if (_consecutiveErrors > Settings.MaxErrors && !Settings.IsShutdown) { Settings.IsShutdown = true; Console.WriteLine("[XUnity.AutoTranslator][ERROR]: More than 5 consecutive errors occurred. Shutting down plugin..."); } })); } for (int i = 0; i < _kickedOff.Count; i++) { _unstartedJobs.Remove(_kickedOff[i]); } _kickedOff.Clear(); }