From 8342c7cdeedbb43810a6a9923e83be95f7f9ffce Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 14 Sep 2023 16:36:28 +0800 Subject: [PATCH] fix: photo caption translate --- .../org/telegram/ui/Components/EditTextCaption.java | 10 +++++++++- .../org/telegram/ui/Components/EditTextEmoji.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextCaption.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextCaption.java index 1850a5d47..b2e2b0d86 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextCaption.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextCaption.java @@ -55,6 +55,7 @@ import org.telegram.ui.ActionBar.AlertDialogDecor; import org.telegram.ui.ActionBar.Theme; import java.util.List; +import java.util.Locale; import cn.hutool.core.util.StrUtil; import tw.nekomimi.nekogram.NekoConfig; @@ -295,8 +296,15 @@ public class EditTextCaption extends EditTextBoldCursor { setText(replaceAt(origin, start, end, TranslateDb.currentInputTarget().query(text))); } else { + Locale to; + Locale toDefault = TranslatorKt.getCode2Locale(NekoConfig.translateInputLang.String()); + if (delegate != null) { + to = TranslateDb.getChatLanguage(delegate.getCurrentChat(), toDefault); + } else { + to = toDefault; + } - Translator.translate(TranslateDb.getChatLanguage(delegate.getCurrentChat(), TranslatorKt.getCode2Locale(NekoConfig.translateInputLang.String())), text, new Translator.Companion.TranslateCallBack() { + Translator.translate(to, text, new Translator.Companion.TranslateCallBack() { AlertDialog status = AlertUtil.showProgress(getContext()); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextEmoji.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextEmoji.java index 16c8cefa2..99f1b9f3c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextEmoji.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextEmoji.java @@ -185,6 +185,17 @@ public class EditTextEmoji extends FrameLayout implements NotificationCenter.Not } } }; + editText.setDelegate(new EditTextCaption.EditTextCaptionDelegate() { + @Override + public void onSpansChanged() { + editText.invalidateEffects(); + } + + @Override + public long getCurrentChat() { + return 0; + } + }); editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); editText.setInputType(editText.getInputType() | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); editText.setFocusable(editText.isEnabled());