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))); }
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); } } }
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); } } }
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())); }
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; }
// 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); }