From 7b91d14870bb9cd104c72b4e38b1d328cf984285 Mon Sep 17 00:00:00 2001 From: Gabby Gurdin Date: Wed, 21 Feb 2024 14:09:52 -0500 Subject: [PATCH] translation updates --- lib/pangea/constants/model_keys.dart | 2 ++ lib/pangea/repo/full_text_translation_repo.dart | 6 ++++++ lib/pangea/widgets/chat/message_text_selection.dart | 2 ++ lib/pangea/widgets/chat/message_translation_card.dart | 4 +++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/pangea/constants/model_keys.dart b/lib/pangea/constants/model_keys.dart index d027bce1d..6f0649dbb 100644 --- a/lib/pangea/constants/model_keys.dart +++ b/lib/pangea/constants/model_keys.dart @@ -51,6 +51,8 @@ class ModelKey { static const String word = "word"; static const String lang = "lang"; static const String deepL = "deepl"; + static const String offset = "offset"; + static const String length = "length"; static const String langCode = 'lang_code'; static const String wordLang = "word_lang"; static const String lemma = "lemma"; diff --git a/lib/pangea/repo/full_text_translation_repo.dart b/lib/pangea/repo/full_text_translation_repo.dart index a781b4b0d..704bb9d63 100644 --- a/lib/pangea/repo/full_text_translation_repo.dart +++ b/lib/pangea/repo/full_text_translation_repo.dart @@ -37,6 +37,8 @@ class FullTextTranslationRequestModel { String userL1; String userL2; bool? deepL; + int? offset; + int? length; FullTextTranslationRequestModel({ required this.text, @@ -45,6 +47,8 @@ class FullTextTranslationRequestModel { required this.userL2, required this.userL1, this.deepL = false, + this.offset, + this.length, }); //PTODO throw error for null @@ -56,6 +60,8 @@ class FullTextTranslationRequestModel { ModelKey.userL2: userL2, ModelKey.userL1: userL1, ModelKey.deepL: deepL, + ModelKey.offset: offset, + ModelKey.length: length, }; } diff --git a/lib/pangea/widgets/chat/message_text_selection.dart b/lib/pangea/widgets/chat/message_text_selection.dart index b41d62cbe..6263738f4 100644 --- a/lib/pangea/widgets/chat/message_text_selection.dart +++ b/lib/pangea/widgets/chat/message_text_selection.dart @@ -32,4 +32,6 @@ class MessageTextSelection { } selectionStream.add(selectedText); } + + int get offset => messageText.indexOf(selectedText!); } diff --git a/lib/pangea/widgets/chat/message_translation_card.dart b/lib/pangea/widgets/chat/message_translation_card.dart index c963dd251..ec24668e3 100644 --- a/lib/pangea/widgets/chat/message_translation_card.dart +++ b/lib/pangea/widgets/chat/message_translation_card.dart @@ -73,11 +73,13 @@ class MessageTranslationCardState extends State { final resp = await FullTextTranslationRepo.translate( accessToken: accessToken, request: FullTextTranslationRequestModel( - text: widget.selection.selectedText!, + text: widget.selection.messageText, tgtLang: translationLangCode()!, userL1: l1Code!, userL2: l2Code!, srcLang: widget.messageEvent.messageDisplayLangCode, + length: widget.selection.selectedText!.length, + offset: widget.selection.offset, ), );