Exemple #1
0
        public static IEnumerator TranslateFullNameCoroutine(this ChaFile chaFile, Action <string> callback)
        {
            var origName = chaFile.GetFullName();

            chaFile.StartMonitoredCoroutine(
                CardNameTranslationManager.Instance.TranslateCardName(origName, new NameScope(chaFile.GetSex()),
                                                                      Handlers.AddNameToCache(origName),
                                                                      r => { callback(r.Succeeded ? r.TranslatedText : string.Empty); }));
            yield break;
        }
Exemple #2
0
        protected virtual IEnumerable <KeyValuePair <string, string> > GetNamesToRegister(ChaFile chaFile)
        {
            var handled = HashSetPool <string> .Get();

            var controller = chaFile.GetTranslationHelperController();

            try
            {
                foreach (var nameEntry in chaFile.EnumerateNames())
                {
                    var name = nameEntry.Value;
                    if (handled.Contains(name))
                    {
                        continue;
                    }
                    handled.Add(name);
                    yield return(new KeyValuePair <string, string>(name, name));

                    if (controller == null)
                    {
                        continue;
                    }
                    var origName = controller.OriginalNames[nameEntry.Key];
                    if (origName.IsNullOrEmpty() || origName == name || handled.Contains(origName))
                    {
                        continue;
                    }
                    handled.Add(origName);
                    yield return(new KeyValuePair <string, string>(origName, origName));
                }

                var fullname = chaFile.GetFullName();
                foreach (var name in new[]
                {
                    fullname, chaFile.GetOriginalFullName(), chaFile.GetFormattedOriginalName()
                })
                {
                    if (handled.Contains(name))
                    {
                        continue;
                    }
                    handled.Add(name);
                    yield return(new KeyValuePair <string, string>(name, name));
                }
            }
            finally
            {
                HashSetPool <string> .Release(handled);
            }
        }
Exemple #3
0
        private IEnumerable <string> GetNamesToRegister(ChaFile chaFile)
        {
            var handled = new HashSet <string>();

            foreach (var name in chaFile.EnumerateNames().Select(n => n.Value))
            {
                if (handled.Contains(name))
                {
                    continue;
                }
                handled.Add(name);
                yield return(name);
            }

            var fullname = chaFile.GetFullName();

            if (handled.Contains(fullname))
            {
                yield break;
            }
            yield return(fullname);
        }
Exemple #4
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);
        }