Пример #1
0
        public bool CardNeedsTranslation(ChaFile file)
        {
            var sex = file.GetSex();

            return(file.EnumerateNames().Any(name =>
                                             StringUtils.ContainsJapaneseChar(name.Value) &&
                                             !NoTranslate[new NameScope(sex, file.GetNameType(name.Key))].Contains(name.Value)));
        }
Пример #2
0
        protected virtual void ApplyTranslations(ChaFile file)
        {
            if (file.TryGetTranslationHelperController(out var controller))
            {
                controller.ApplyTranslations();
                return;
            }

            var sex = file.GetSex();

            // partially loaded, no controller available
            foreach (var entry in file.EnumerateNames())
            {
                var scope = new NameScope(sex, file.GetNameType(entry.Key));
                if (TryGetRecentTranslation(scope, entry.Value, out var translatedName) &&
                    !TranslationHelper.NameStringComparer.Equals(translatedName, entry.Value))
                {
                    file.SetName(entry.Key, translatedName);
                }
            }
        }
Пример #3
0
        private void ApplyTranslations(ChaFile file)
        {
            if (file.TryGetTranslationHelperController(out var controller))
            {
                controller.ApplyTranslations();
                return;
            }

            var sex = file.GetSex();

            // partially loaded, no controller available
            foreach (var entry in file.EnumerateNames())
            {
                var scope = new NameScope(sex, file.GetNameType(entry.Key));
                if (NoTranslate[scope].Contains(entry.Value))
                {
                    continue;
                }
                if (RecentTranslationsByName[scope].TryGetValue(entry.Value, out var translatedName))
                {
                    file.SetName(entry.Key, translatedName);
                }
            }
        }
Пример #4
0
        public static IEnumerator TranslateFullNameCoroutine(this ChaFile chaFile, Action <string> callback)
        {
            int started;

            var nameTypes = new[] { "lastname", "firstname" };

            var names = nameTypes.Select(n => string.Empty).ToList();

            started = names.Count;
            for (var i = 0; i < nameTypes.Length; i++)
            {
                var dest          = i;
                var nameTypeIndex = GeBoAPI.Instance.ChaFileNameToIndex(nameTypes[i]);
                var name          = names[i] = chaFile.GetName(nameTypeIndex);

                chaFile.StartMonitoredCoroutine(
                    CardNameTranslationManager.Instance.TranslateCardName(name,
                                                                          new NameScope(chaFile.GetSex(), chaFile.GetNameType(nameTypeIndex)), r =>
                {
                    if (r.Succeeded)
                    {
                        names[dest] = r.TranslatedText;
                    }

                    started--;
                }));
            }

            bool IsDone()
            {
                return(started == 0);
            }

            yield return(new WaitUntil(IsDone));

            if (TranslationHelper.KK_GivenNameFirst.Value)
            {
                names.Reverse();
            }

            callback(string.Join(TranslationHelper.SpaceJoiner, names.ToArray()));
        }