Пример #1
0
 private static bool TryApplyAlternateTranslation(NameScope scope, CharaFileInfo charaFileInfo, string origName,
                                                  bool fast)
 {
     return(charaFileInfo != null &&
            Configuration.AlternateStudioCharaLoaderTranslators.Any(tryTranslate =>
                                                                    tryTranslate(scope, charaFileInfo, origName, fast)));
 }
Пример #2
0
        private static bool TryApplyBetterCharaLoaderNames(CharaFileInfo charaFileInfo, string origName)
        {
            if (!KK_StudioCharaLoaderNames.TryGetValue(origName, out var translatedName) ||
                string.IsNullOrEmpty(translatedName))
            {
                return(false);
            }

            charaFileInfo.node.text = charaFileInfo.name = translatedName;
            return(true);
        }
Пример #3
0
        private static IEnumerator TranslateDisplayListEntryCoroutine(CharaFileInfo entry, NameScope scope,
                                                                      Action callback = null)
        {
            Logger.DebugLogDebug(
                $"{nameof(TranslateDisplayListEntryCoroutine)}: entry={entry}, scope={scope}, callback={callback}");
            var limitCoroutine = TranslationHelper.Instance.StartCoroutine(TreeNodeLimiter.Start());

            if (limitCoroutine != null)
            {
                yield return(limitCoroutine);
            }
            yield return(TranslationHelper.Instance.StartCoroutine(TranslateDisplayListEntry(entry, scope)));

            TreeNodeLimiter.EndImmediately();
            callback?.Invoke();
        }
Пример #4
0
        public static Action <string> MakeCachingCallbackWrapper(string origName, CharaFileInfo charaFileInfo,
                                                                 NameScope scope, Action <string> callback = null)
        {
            var path = charaFileInfo.file;

            void CharaFileInfoCachingCallbackWrapper(string translationResult)
            {
                Logger.DebugLogDebug(
                    $"{nameof(CharaFileInfoCachingCallbackWrapper)}: translationResult={translationResult}, origName={origName}, path={path}, callback={callback}");
                if (!translationResult.IsNullOrEmpty() &&
                    !TranslationHelper.NameStringComparer.Equals(translationResult, origName) &&
                    !path.IsNullOrEmpty())
                {
                    CacheRecentTranslation(scope, path, translationResult);
                }

                callback?.Invoke(translationResult);
            }

            return(CharaFileInfoCachingCallbackWrapper);
        }
Пример #5
0
 private static bool TryApplyAlternateTranslation(CharaFileInfo charaFileInfo, string origName)
 {
     return(Configuration.AlternateStudioCharaLoaderTranslators.Any(tryTranslate =>
                                                                    tryTranslate(charaFileInfo, origName)));
 }
Пример #6
0
        private static bool TryApplyLoadCharaFileTranslatedMap(NameScope sexOnlyScope, CharaFileInfo charaFileInfo,
                                                               string origName, bool fastOnly)
        {
            if (!Translation.Configuration.LoadCharaFileTranslatedMap[sexOnlyScope]
                .TryGetValue(origName, out var translatedName) ||
                string.IsNullOrEmpty(translatedName))
            {
                return(false);
            }

            charaFileInfo.node.text = charaFileInfo.name = translatedName;
            return(true);
        }
Пример #7
0
        private static IEnumerator TranslateDisplayListEntry(CharaFileInfo entry, NameScope scope,
                                                             Action <string> callback = null)
        {
            Logger.DebugLogDebug(
                $"{nameof(TranslateDisplayListEntry)}: entry={entry}, scope={scope}, callback={callback}");
            if (entry == null)
            {
                yield break;
            }

            var origName = entry.name;

            var wrappedCallback =
                CharaFileInfoTranslationManager.MakeCachingCallbackWrapper(origName, entry, scope, callback);


            void UpdateName(CharaFileInfo charaFileInfo, string translatedName)
            {
                Logger.DebugLogDebug(
                    $"{nameof(TranslateDisplayListEntry)}:{nameof(UpdateName)}: charaFileInfo={charaFileInfo}, translatedName={translatedName}");
                charaFileInfo.name = charaFileInfo.node.text = translatedName;
            }

            void HandleResult(CharaFileInfo charaFileInfo, ITranslationResult result)
            {
                Logger.DebugLogDebug(
                    $"{nameof(TranslateDisplayListEntry)}:{nameof(HandleResult)}: charaFileInfo={charaFileInfo}, result={result}");
                if (!result.Succeeded)
                {
                    return;
                }
                UpdateName(charaFileInfo, result.TranslatedText);
            }

            if (TryApplyAlternateTranslation(scope, entry, origName, true))
            {
                Logger.DebugLogDebug($"{nameof(TranslateDisplayListEntry)}: applied alternate translation");
                wrappedCallback(entry.name);
                yield break;
            }

            if (TranslationHelper.TryFastTranslateFullName(scope, origName, entry.file, out var fastName))
            {
                Logger.DebugLogDebug($"{nameof(TranslateDisplayListEntry)}: fast translated!");
                UpdateName(entry, fastName);
                wrappedCallback(entry.name);
                yield break;
            }

            Logger.DebugLogDebug($"{nameof(TranslateDisplayListEntry)}: not fast translated!");

            yield return(null);

            void AsyncHandler(ITranslationResult result)
            {
                Logger.DebugLogDebug(
                    $"{nameof(TranslateDisplayListEntry)}:{nameof(AsyncHandler)}: result={result}, entry={entry}");
                // async handler, things may have gone null
                try
                {
                    HandleResult(entry, result);
                    TryApplyAlternateTranslation(scope, entry, origName, false);
                    wrappedCallback(entry.name);
                }
                catch (NullReferenceException err)
                {
                    Logger.LogDebug(
                        $"{nameof(TranslateDisplayListEntry)}:{nameof(AsyncHandler)}: unable to apply translation: {err.Message} (entry may no longer exist)");
                }
            }

            TranslationHelper.Instance.StartCoroutine(
                TranslationHelper.CardNameManager.TranslateFullName(origName, scope, AsyncHandler));
        }