Skip to content

Commit

Permalink
Merge pull request #408 from pangeachat/improve-interactive-translator
Browse files Browse the repository at this point in the history
Improve interactive translator
  • Loading branch information
ggurdin authored Jun 28, 2024
2 parents 66f7da0 + b95080c commit 3bdd3ac
Show file tree
Hide file tree
Showing 28 changed files with 626 additions and 219 deletions.
20 changes: 16 additions & 4 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2894,21 +2894,23 @@
"type": "text",
"placeholders": {}
},
"helpMeTranslate": "Help me translate!",
"helpMeTranslate": "Yes!",
"@helpMeTranslate": {
"type": "text",
"placeholders": {}
},
"needsItShortMessage": "Try interactive translation!",
"needsItShortMessage": "Out of target",
"needsIGCShortMessage": "Try interactive grammar assistance!",
"@needsItShortMessage": {
"type": "text",
"placeholders": {}
},
"needsItMessage": "This message has too many words in your base language.",
"needsItMessage": "Wait, that's not {targetLanguage}! Do you need help translating?",
"@needsItMessage": {
"type": "text",
"placeholders": {}
"placeholders": {
"targetLanguage": {}
}
},
"needsIgcMessage": "This message has a grammar error.",
"tokenTranslationTitle": "A word is in your base language.",
Expand Down Expand Up @@ -4069,5 +4071,15 @@
"placeholders": {
"currentLanguage": {}
}
},
"interactiveTranslatorAutoPlaySliderHeader": "Autoplay translation",
"@interactiveTranslatorAutoPlaySliderHeader": {
"type": "text",
"placeholders": {}
},
"interactiveTranslatorAutoPlayDesc": "Launches the interactive translator without asking.",
"@interactiveTranslatorAutoPlayDesc": {
"type": "text",
"placeholders": {}
}
}
21 changes: 19 additions & 2 deletions assets/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,17 @@
"type": "text",
"placeholders": {}
},
"interactiveTranslatorAutoPlaySliderHeader": "Traducción de reproducción automática",
"interactiveTranslatorAutoPlay": "Traductora interactiva de reproducción automática",
"@interactiveTranslatorAutoPlay": {
"type": "text",
"placeholders": {}
},
"interactiveTranslatorAutoPlayDesc": "Inicia el traductor interactivo sin preguntar.",
"@interactiveTranslatorAutoPlayDesc": {
"type": "text",
"placeholders": {}
},
"grammarAssistance": "Asistencia gramatical",
"@grammarAssistance": {
"type": "text",
Expand Down Expand Up @@ -3126,10 +3137,16 @@
"translationSeemsFinished": "La traducción parece estar terminada.",
"needsItShortMessage": "¡Pruebe la traducción interactiva!",
"needsIGCShortMessage": "¡Pruebe el corrector gramatical interactivo!",
"needsItMessage": "Este mensaje tiene demasiadas palabras en su idioma base.",
"needsItMessage": "Espera, ¡ese no es {targetLanguage}! ¿Necesitas ayuda para traducir?",
"@needsItMessage": {
"type": "text",
"placeholders": {
"targetLanguage": {}
}
},
"needsIgcMessage": "Este mensaje tiene un error gramatical.",
"tokenTranslationTitle": "Una palabra está en su idioma base.",
"helpMeTranslate": "¡Ayúdeme a traducir!",
"helpMeTranslate": "¡!",
"setToPublicSettingsTitle": "¿Quiere encontrar un compañero de conversación?",
"setToPublicSettingsDesc": "Antes de que pueda buscar un compañero de conversación, debe configurar la visibilidad de su perfil como pública.",
"publicProfileTitle": "Perfil público",
Expand Down
Binary file added assets/pangea/bot_faces/pangea_bot.riv
Binary file not shown.
4 changes: 0 additions & 4 deletions lib/pages/chat/chat_input_row.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:animations/animations.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
import 'package:fluffychat/pangea/choreographer/widgets/it_bar.dart';
import 'package:fluffychat/pangea/choreographer/widgets/send_button.dart';
import 'package:fluffychat/pangea/constants/language_keys.dart';
import 'package:fluffychat/utils/platform_infos.dart';
Expand Down Expand Up @@ -55,9 +54,6 @@ class ChatInputRow extends StatelessWidget {

return Column(
children: [
ITBar(
choreographer: controller.choreographer,
),
Row(
// crossAxisAlignment: CrossAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';

import '../../pangea/choreographer/widgets/it_bar.dart';
import '../../utils/stream_extension.dart';
import 'chat_emoji_picker.dart';
import 'chat_input_row.dart';
Expand Down Expand Up @@ -440,6 +441,9 @@ class ChatView extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: [
const ConnectionStatusHeader(),
ITBar(
choreographer: controller.choreographer,
),
ReactionsPicker(controller),
ReplyDisplay(controller),
ChatInputRow(controller),
Expand Down
5 changes: 5 additions & 0 deletions lib/pangea/choreographer/controllers/choreographer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:fluffychat/pangea/models/language_detection_model.dart';
import 'package:fluffychat/pangea/models/representation_content_model.dart';
import 'package:fluffychat/pangea/models/space_model.dart';
import 'package:fluffychat/pangea/models/tokens_event_content_model.dart';
import 'package:fluffychat/pangea/models/user_model.dart';
import 'package:fluffychat/pangea/utils/any_state_holder.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/utils/overlay.dart';
Expand Down Expand Up @@ -522,6 +523,10 @@ class Choreographer {
chatController.room,
);

bool get itAutoPlayEnabled => pangeaController.pStoreService.read(
MatrixProfile.itAutoPlay.title,
) ?? false;

bool get definitionsEnabled =>
pangeaController.permissionsController.isToolEnabled(
ToolSetting.definitions,
Expand Down
11 changes: 10 additions & 1 deletion lib/pangea/choreographer/controllers/igc_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ class IgcController {
const int firstMatchIndex = 0;
final PangeaMatch match = igcTextData!.matches[firstMatchIndex];

if (
match.isITStart &&
choreographer.itAutoPlayEnabled &&
igcTextData != null
) {
choreographer.onITStart(igcTextData!.matches[firstMatchIndex]);
return;
}

OverlayUtil.showPositionedCard(
context: context,
cardToShow: SpanCard(
Expand All @@ -189,7 +198,7 @@ class IgcController {
),
roomId: choreographer.roomId,
),
cardSize: match.isITStart ? const Size(350, 220) : const Size(350, 400),
cardSize: match.isITStart ? const Size(350, 260) : const Size(350, 400),
transformTargetId: choreographer.inputTransformTargetKey,
);
}
Expand Down
44 changes: 18 additions & 26 deletions lib/pangea/choreographer/controllers/it_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ITController {
Choreographer choreographer;

bool _isOpen = false;
bool _willOpen = false;
bool _isEditingSourceText = false;
bool showChoiceFeedback = false;

Expand All @@ -36,6 +37,7 @@ class ITController {

void clear() {
_isOpen = false;
_willOpen = false;
showChoiceFeedback = false;
_isEditingSourceText = false;

Expand All @@ -54,18 +56,17 @@ class ITController {
}

Future<void> initializeIT(ITStartData itStartData) async {
_willOpen = true;
Future.delayed(const Duration(microseconds: 100), () {
_isOpen = true;
});
_itStartData = itStartData;
}

void closeIT() {
//if they close it before choosing anything, just put their text back
//if they close it before completing, just put their text back
//PTODO - explore using last itStep
if (choreographer.currentText.isEmpty) {
choreographer.textController.text = sourceText ?? "";
}
choreographer.textController.text = sourceText ?? "";
clear();
}

Expand Down Expand Up @@ -217,31 +218,19 @@ class ITController {

Future<void> onEditSourceTextSubmit(String newSourceText) async {
try {
sourceText = newSourceText;

_isOpen = true;
_isEditingSourceText = false;
final String currentText = choreographer.currentText;
_itStartData = ITStartData(newSourceText, choreographer.l1LangCode);
completedITSteps = [];
currentITStep = null;
nextITStep = null;
goldRouteTracker = GoldRouteTracker.defaultTracker;
payLoadIds = [];

choreographer.startLoading();
_setSourceText();
getTranslationData(false);

final List<ITResponseModel> responses = await Future.wait([
_customInputTranslation(""),
_customInputTranslation(choreographer.currentText),
]);
if (responses[0].goldContinuances != null &&
responses[0].goldContinuances!.isNotEmpty) {
goldRouteTracker = GoldRouteTracker(
responses[0].goldContinuances!,
sourceText!,
);
}
currentITStep = CurrentITStep(
sourceText: sourceText!,
currentText: currentText,
responseModel: responses[1],
storedGoldContinuances: goldRouteTracker.continuances,
);

_addPayloadId(responses[1]);
} catch (err, stack) {
debugger(when: kDebugMode);
if (err is! http.Response) {
Expand All @@ -252,6 +241,7 @@ class ITController {
);
} finally {
choreographer.stopLoading();
choreographer.textController.text = "";
}
}

Expand Down Expand Up @@ -334,6 +324,8 @@ class ITController {

bool get isOpen => _isOpen;

bool get willOpen => _willOpen;

String get targetLangCode => choreographer.l2LangCode!;

String get sourceLangCode => choreographer.l1LangCode!;
Expand Down
Loading

0 comments on commit 3bdd3ac

Please sign in to comment.