diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 08e36316d..09fa273e0 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -4068,7 +4068,7 @@ "hintTitle": "Hint:", "speechToTextBody": "See how well you did by looking at your Accuracy and Words Per Minute scores", "previous": "Previous", - "versionNotFound": "Version Not Found", + "versionNotFound": "Version Not Found", "fetchingVersion": "Fetching version...", "versionFetchError": "Error fetching version", "connectedToStaging": "Connected to Staging", @@ -4104,5 +4104,6 @@ "type": "text", "placeholders": {} }, - "changeAnalyticsView": "Change Analytics View" + "changeAnalyticsView": "Change Analytics View", + "l1TranslationBody": "Oops! It looks like this message wasn't sent in your target language. Messages not sent in your target language will not be translated." } \ No newline at end of file diff --git a/lib/pangea/enum/instructions_enum.dart b/lib/pangea/enum/instructions_enum.dart index c684d5b14..376d004b5 100644 --- a/lib/pangea/enum/instructions_enum.dart +++ b/lib/pangea/enum/instructions_enum.dart @@ -7,7 +7,6 @@ enum InstructionsEnum { clickMessage, blurMeansTranslate, tooltipInstructions, - speechToText, } extension Copy on InstructionsEnum { @@ -21,8 +20,6 @@ extension Copy on InstructionsEnum { return L10n.of(context)!.blurMeansTranslateTitle; case InstructionsEnum.tooltipInstructions: return L10n.of(context)!.tooltipInstructionsTitle; - case InstructionsEnum.speechToText: - return L10n.of(context)!.hintTitle; } } @@ -34,8 +31,6 @@ extension Copy on InstructionsEnum { return L10n.of(context)!.clickMessageBody; case InstructionsEnum.blurMeansTranslate: return L10n.of(context)!.blurMeansTranslateBody; - case InstructionsEnum.speechToText: - return L10n.of(context)!.speechToTextBody; case InstructionsEnum.tooltipInstructions: return PlatformInfos.isMobile ? L10n.of(context)!.tooltipInstructionsMobileBody @@ -43,3 +38,19 @@ extension Copy on InstructionsEnum { } } } + +enum InlineInstructions { + speechToText, + l1Translation, +} + +extension InlineInstructionsExtension on InlineInstructions { + String body(BuildContext context) { + switch (this) { + case InlineInstructions.speechToText: + return L10n.of(context)!.speechToTextBody; + case InlineInstructions.l1Translation: + return L10n.of(context)!.l1TranslationBody; + } + } +} diff --git a/lib/pangea/utils/inline_tooltip.dart b/lib/pangea/utils/inline_tooltip.dart index 253288a84..21fc7321a 100644 --- a/lib/pangea/utils/inline_tooltip.dart +++ b/lib/pangea/utils/inline_tooltip.dart @@ -34,7 +34,7 @@ class InlineTooltip extends StatelessWidget { child: Padding( padding: const EdgeInsets.all(10), child: RichText( - textAlign: TextAlign.justify, + textAlign: TextAlign.center, text: TextSpan( children: [ const WidgetSpan( @@ -50,6 +50,7 @@ class InlineTooltip extends StatelessWidget { text: body, style: TextStyle( color: Theme.of(context).colorScheme.onSurface, + height: 1.5, ), ), ], diff --git a/lib/pangea/utils/instructions.dart b/lib/pangea/utils/instructions.dart index 382268082..948d6a1e4 100644 --- a/lib/pangea/utils/instructions.dart +++ b/lib/pangea/utils/instructions.dart @@ -18,13 +18,13 @@ class InstructionsController { // We have these three methods to make sure that the instructions are not shown too much /// Instruction popup was closed by the user - final Map _instructionsClosed = {}; + final Map _instructionsClosed = {}; /// Instruction popup has already been shown this session - final Map _instructionsShown = {}; + final Map _instructionsShown = {}; /// Returns true if the user requested this popup not be shown again - bool? toggledOff(InstructionsEnum key) => + bool? toggledOff(String key) => _pangeaController.pStoreService.read(key.toString()); InstructionsController(PangeaController pangeaController) { @@ -33,18 +33,17 @@ class InstructionsController { /// Returns true if the instructions were closed /// or turned off by the user via the toggle switch - bool wereInstructionsTurnedOff(InstructionsEnum key) => + bool wereInstructionsTurnedOff(String key) => toggledOff(key) ?? _instructionsClosed[key] ?? false; - void turnOffInstruction(InstructionsEnum key) => - _instructionsClosed[key] = true; + void turnOffInstruction(String key) => _instructionsClosed[key] = true; Future updateEnableInstructions( - InstructionsEnum key, + String key, bool value, ) async => await _pangeaController.pStoreService.save( - key.toString(), + key, value, ); @@ -56,12 +55,12 @@ class InstructionsController { String transformTargetKey, [ bool showToggle = true, ]) async { - if (_instructionsShown[key] ?? false) { + if (_instructionsShown[key.toString()] ?? false) { return; } - _instructionsShown[key] = true; + _instructionsShown[key.toString()] = true; - if (wereInstructionsTurnedOff(key)) { + if (wereInstructionsTurnedOff(key.toString())) { return; } if (L10n.of(context) == null) { @@ -90,7 +89,7 @@ class InstructionsController { CardHeader( text: key.title(context), botExpression: BotExpression.idle, - onClose: () => {_instructionsClosed[key] = true}, + onClose: () => {_instructionsClosed[key.toString()] = true}, ), const SizedBox(height: 10.0), Expanded( @@ -118,10 +117,10 @@ class InstructionsController { /// which displays hint text defined in the enum extension Widget getInstructionInlineTooltip( BuildContext context, - InstructionsEnum key, + InlineInstructions key, VoidCallback onClose, ) { - if (wereInstructionsTurnedOff(key)) { + if (wereInstructionsTurnedOff(key.toString())) { return const SizedBox(); } @@ -134,7 +133,7 @@ class InstructionsController { } return InlineTooltip( - body: InstructionsEnum.speechToText.body(context), + body: InlineInstructions.speechToText.body(context), onClose: onClose, ); } @@ -167,11 +166,12 @@ class InstructionsToggleState extends State { return SwitchListTile.adaptive( activeColor: AppConfig.activeToggleColor, title: Text(L10n.of(context)!.doNotShowAgain), - value: pangeaController.instructions - .wereInstructionsTurnedOff(widget.instructionsKey), + value: pangeaController.instructions.wereInstructionsTurnedOff( + widget.instructionsKey.toString(), + ), onChanged: ((value) async { await pangeaController.instructions.updateEnableInstructions( - widget.instructionsKey, + widget.instructionsKey.toString(), value, ); setState(() {}); diff --git a/lib/pangea/widgets/chat/message_speech_to_text_card.dart b/lib/pangea/widgets/chat/message_speech_to_text_card.dart index a26a36658..3c06a45f3 100644 --- a/lib/pangea/widgets/chat/message_speech_to_text_card.dart +++ b/lib/pangea/widgets/chat/message_speech_to_text_card.dart @@ -67,7 +67,11 @@ class MessageSpeechToTextCardState extends State { void closeHint() { MatrixState.pangeaController.instructions.turnOffInstruction( - InstructionsEnum.speechToText, + InlineInstructions.speechToText.toString(), + ); + MatrixState.pangeaController.instructions.updateEnableInstructions( + InlineInstructions.speechToText.toString(), + true, ); setState(() {}); } @@ -204,7 +208,7 @@ class MessageSpeechToTextCardState extends State { ), MatrixState.pangeaController.instructions.getInstructionInlineTooltip( context, - InstructionsEnum.speechToText, + InlineInstructions.speechToText, closeHint, ), ], diff --git a/lib/pangea/widgets/chat/message_translation_card.dart b/lib/pangea/widgets/chat/message_translation_card.dart index 31b6addb2..fd80df134 100644 --- a/lib/pangea/widgets/chat/message_translation_card.dart +++ b/lib/pangea/widgets/chat/message_translation_card.dart @@ -1,8 +1,10 @@ +import 'package:fluffychat/pangea/enum/instructions_enum.dart'; import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart'; import 'package:fluffychat/pangea/models/representation_content_model.dart'; import 'package:fluffychat/pangea/repo/full_text_translation_repo.dart'; import 'package:fluffychat/pangea/utils/bot_style.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; +import 'package:fluffychat/pangea/utils/inline_tooltip.dart'; import 'package:fluffychat/pangea/widgets/chat/message_text_selection.dart'; import 'package:fluffychat/pangea/widgets/chat/toolbar_content_loading_indicator.dart'; import 'package:fluffychat/pangea/widgets/igc/card_error_widget.dart'; @@ -119,6 +121,17 @@ class MessageTranslationCardState extends State { } } + void closeHint() { + MatrixState.pangeaController.instructions.turnOffInstruction( + InlineInstructions.l1Translation.toString(), + ); + MatrixState.pangeaController.instructions.updateEnableInstructions( + InlineInstructions.l1Translation.toString(), + true, + ); + setState(() {}); + } + @override Widget build(BuildContext context) { if (!_fetchingRepresentation && @@ -127,18 +140,35 @@ class MessageTranslationCardState extends State { return const CardErrorWidget(); } + final bool showWarning = l2Code != null && + !widget.immersionMode && + widget.messageEvent.originalSent?.langCode != l2Code && + !MatrixState.pangeaController.instructions.wereInstructionsTurnedOff( + InlineInstructions.l1Translation.toString(), + ); + return Container( child: _fetchingRepresentation ? const ToolbarContentLoadingIndicator() - : selectionTranslation != null - ? Text( - selectionTranslation!, - style: BotStyle.text(context), - ) - : Text( - repEvent!.text, - style: BotStyle.text(context), - ), + : Column( + children: [ + selectionTranslation != null + ? Text( + selectionTranslation!, + style: BotStyle.text(context), + ) + : Text( + repEvent!.text, + style: BotStyle.text(context), + ), + const SizedBox(height: 10), + if (showWarning) + InlineTooltip( + body: InlineInstructions.l1Translation.body(context), + onClose: closeHint, + ), + ], + ), ); } }