TrackTranslationCoroutine() public méthode

public TrackTranslationCoroutine ( NameTranslationCoroutine translationCoroutine, TranslationHelperPlugin.NameScope scope, string trackedKey ) : IEnumerator
translationCoroutine NameTranslationCoroutine
scope TranslationHelperPlugin.NameScope
trackedKey string
Résultat IEnumerator
Exemple #1
0
        public IEnumerator TranslateFileInfo(ICharaFileInfo fileInfo, params TranslationResultHandler[] callbacks)
        {
            var scope        = new NameScope(fileInfo.Sex);
            var path         = fileInfo.FullPath;
            var originalName = fileInfo.Name;
            var done         = false;
            var tmpCallbacks = callbacks.ToList();

            _pathsInProgress.Add(path);


            var cacheWrapper = MakeCachingCallbackWrapper(fileInfo);

            void DoneHandler(ITranslationResult result)
            {
                _pathsInProgress.Remove(path);
                if (result.Succeeded)
                {
                    cacheWrapper(result.TranslatedText);
                    CardNameTranslationManager.CacheRecentTranslation(scope, originalName, result.TranslatedText);
                    // must be set after CacheRecentTranslation
                    fileInfo.SafeNameUpdate(path, originalName, result.TranslatedText);
                }

                done = true;
            }

            tmpCallbacks.Add(DoneHandler);
            tmpCallbacks.Add(Handlers.AddNameToAutoTranslationCache(originalName));

            IEnumerator WhileNotDone()
            {
                while (!done)
                {
                    yield return(null);
                }
            }

            IEnumerator TranslationCoroutine(IEnumerable <TranslationResultHandler> handlers)
            {
                if (TryGetRecentTranslation(scope, path, out var cachedName))
                {
                    var result = new TranslationResult(originalName, cachedName);
                    if (result.Succeeded)
                    {
                        fileInfo.SafeNameUpdate(path, originalName, cachedName);
                    }

                    handlers.CallHandlers(result);
                    yield break;
                }

                yield return(null);

                if (!StringUtils.ContainsJapaneseChar(originalName))
                {
                    handlers.CallHandlers(new TranslationResult(false, originalName));
                    yield break;
                }

                var tmpHandlers = handlers.ToList();

                tmpHandlers.Add(_ => TranslateFileInfoLimiter.EndImmediately());
                yield return(TranslationHelper.Instance.StartCoroutine(
                                 TranslateFileInfoLimiter.Start().AppendCo(
                                     CardNameTranslationManager.Instance.TranslateFullName(
                                         originalName, scope, tmpHandlers.ToArray()))));
            }

            TranslationHelper.Instance.StartCoroutine(
                _pathTracker.TrackTranslationCoroutine(TranslationCoroutine, scope, path, tmpCallbacks));

            yield return(WhileNotDone());
        }