public static TranslationResultHandler UpdateCardName(ChaFile chaFile, int nameIndex) { void UpdateCardNameHandler(ITranslationResult result) { if (!result.Succeeded || string.IsNullOrEmpty(result.TranslatedText) || chaFile.GetName(nameIndex) == result.TranslatedText) { return; } chaFile.SetTranslatedName(nameIndex, result.TranslatedText); } return(UpdateCardNameHandler); }
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())); }
internal CardNameCacheKey(ChaFile chaFile) : this(chaFile.GetName("lastname"), chaFile.GetName("firstname")) { }
public static string GetName(this ChaFile chaFile, string nameType) { return(chaFile.GetName(GeBoAPI.Instance.ChaFileNameToIndex(nameType))); }
public static string GetOriginalFullName(this ChaFile chaFile) { return(chaFile.TryGetTranslationHelperController(out var controller) ? controller.GetOriginalFullName() #if KK || KKS : string.Concat(chaFile.GetName("lastname"), " ", chaFile.GetName("firstname")));
// 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); }