Ejemplo n.º 1
0
        public static Action <string> MakeCachingCallbackWrapper(string origName, ChaFile chaFile, NameScope scope,
                                                                 Action <string> callback = null)
        {
            var fullPath = chaFile.GetFullPath();

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

                callback?.Invoke(translationResult);
            }

            return(ChaFileCachingCallbackWrapper);
        }
Ejemplo n.º 2
0
        // ReSharper disable Unity.PerformanceAnalysis
        public bool TryTranslateCardNames(ChaFile chaFile, out Dictionary <string, string> result)
        {
            var origName = chaFile.GetFullName();

            if (!_hasEntries)
            {
                result = null;
                return(false);
            }

            void PopulateResult(IDictionary <string, string> output, string nameType, string nameValue)
            {
                if (nameValue != null)
                {
                    output[nameType] = nameValue;
                }
            }

            result = null;
            var key = new CardNameCacheKey(chaFile);
            var sex = chaFile.GetSex();

            if (!_cardCache[sex].TryGetValue(key, out var match))
            {
                return(false);
            }


            result = new Dictionary <string, string>(GeBoAPI.Instance.ChaFileNameCount);
            PopulateResult(result, "fullname", match.FullName);
            PopulateResult(result, "firstname", match.GivenName);
            PopulateResult(result, "lastname", match.FamilyName);

            var fullName = BuildFullName(match);

            if (!StringUtils.ContainsJapaneseChar(fullName))
            {
                CardNameTranslationManager.CacheRecentTranslation(new NameScope(sex), origName, fullName);
                var fullPath = chaFile.GetFullPath();
                if (!string.IsNullOrEmpty(fullPath))
                {
                    CharaFileInfoTranslationManager.CacheRecentTranslation(
                        new NameScope(chaFile.GetSex()), fullPath, fullName);
                }
            }


            var origNick = chaFile.GetName("nickname");

            if (string.IsNullOrEmpty(origNick))
            {
                return(true);
            }

            if (_nickNameCache[sex].TryGetValue(key, out var nickLookup) &&
                nickLookup.TryGetValue(origNick, out var translatedNick))
            {
                PopulateResult(result, "nickname", translatedNick);
            }
            else if (key.GivenName == origNick)
            {
                PopulateResult(result, "nickname", match.GivenName);
            }

            return(true);
        }