public static bool TryTranslateFullName(IComponentTranslationContext context, Predicate <Text> predicate, Func <ChaControl> charGetter, CharacterSex sex = CharacterSex.Unspecified) { if (!(context.Component is Text textComponent)) { return(false); } if (!predicate(textComponent)) { return(false); } var originalText = context.OriginalText; void ResultHandler(ITranslationResult result) { // this fires with a simple full-name translation, which is less likely to be accurate than // some other translation options in games with split first/last names, so if it's already changed // we discard it here. if (result.Succeeded) { textComponent.SafeProc(tc => { if (tc.text == result.TranslatedText) { return; } if (tc.text != originalText) { Logger?.DebugLogDebug( $"text already updated from '{originalText}' to '{tc.text}', discarding '{result.TranslatedText}'"); return; } tc.text = result.TranslatedText; }); } } var chaControl = charGetter(); var scope = chaControl != null ? new NameScope((CharacterSex)chaControl.sex) : sex != CharacterSex.Unspecified ? new NameScope(sex) : NameScope.DefaultNameScope; if (TranslationHelper.TryFastTranslateFullName(scope, context.OriginalText, out var translatedName)) { context.OverrideTranslatedText(translatedName); } else { Logger?.DebugLogDebug( $"{nameof(ComponentTranslationHelpers)}.{nameof(TryTranslateFullName)}: attempting async translation for {context.OriginalText} ({chaControl})"); textComponent.StartCoroutine(TranslateFullNameCoroutine(context.OriginalText, chaControl, scope, textComponent, ResultHandler)); } return(true); }
private static void SelectTextCallback(IComponentTranslationContext context) { if (!_pointerCallbackRegistered || !MakerAPI.InsideMaker) { return; } // ReSharper disable once InvertIf if (ComponentTranslationHelpers.TryTranslateFullName(context, t => t != null && PointerCallbackActiveTexts.Contains(t), () => null, (CharacterSex)MakerAPI.GetMakerSex())) { context.IgnoreComponent(); } }
private static void AdvTranslationCallback(IComponentTranslationContext context) { if (context.OriginalText.IsNullOrEmpty()) { return; } bool IsNameLabel(Text textComponent) { #if AI return(textComponent.name == "NameLabel"); #elif HS2 return(textComponent.name == "Name"); #else return(false); #endif } ComponentTranslationHelpers.TryTranslateFullName(context, IsNameLabel, GetCurrentAdvSceneCharacter); }
private static void CharaListHandler(IComponentTranslationContext obj) { // TODO: migrate to a version of this call /* * if (ComponentTranslationHelpers.TryTranslateFullName(obj, * ShouldHandleCharaListText, * ()=>null, * * t => t != null && PointerCallbackActiveTexts.Contains(t), * () => null, (CharacterSex)MakerAPI.GetMakerSex())) * { * obj.IgnoreComponent(); * } */ if (!TranslationHelper.Instance.CurrentCardLoadTranslationEnabled || CharaListsInProgress.Count == 0) { return; } var textComponent = obj.Component as Text; if (textComponent == null) { return; } var charaList = textComponent.GetComponentInParent <CharaList>(); if (charaList == null || !CharaListsInProgress.Contains(charaList)) { return; } CharacterSex sex; if (charaList.name.EndsWith("_Male", StringComparison.OrdinalIgnoreCase)) { sex = CharacterSex.Male; } else if (charaList.name.EndsWith("_Female", StringComparison.OrdinalIgnoreCase)) { sex = CharacterSex.Female; } else { return; } /* * var scope = new NameScope(sex); * if (TranslationHelper.TryFastTranslateFullName(scope, textComponent.text, out var translatedName)) * { * obj.OverrideTranslatedText(translatedName); * obj.IgnoreComponent(); * } */ if (ComponentTranslationHelpers.TryTranslateFullName(obj, ShouldHandleCharaListText, () => null, sex)) { obj.IgnoreComponent(); } }