better handling for localizations in instruction popups
This commit is contained in:
parent
70fd9e9f2e
commit
a76eb8cbe9
3 changed files with 50 additions and 71 deletions
|
|
@ -4,7 +4,6 @@ import 'package:fluffychat/pangea/utils/error_handler.dart';
|
|||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
enum InstructionsEnum {
|
||||
|
|
@ -19,24 +18,16 @@ enum InstructionsEnum {
|
|||
}
|
||||
|
||||
extension InstructionsEnumExtension on InstructionsEnum {
|
||||
String title(BuildContext context) {
|
||||
if (!context.mounted) {
|
||||
ErrorHandler.logError(
|
||||
e: Exception("Context not mounted"),
|
||||
m: 'InstructionsEnumExtension.title for $this',
|
||||
);
|
||||
debugger(when: kDebugMode);
|
||||
return '';
|
||||
}
|
||||
String title(L10n l10n) {
|
||||
switch (this) {
|
||||
case InstructionsEnum.itInstructions:
|
||||
return L10n.of(context)!.itInstructionsTitle;
|
||||
return l10n.itInstructionsTitle;
|
||||
case InstructionsEnum.clickMessage:
|
||||
return L10n.of(context)!.clickMessageTitle;
|
||||
return l10n.clickMessageTitle;
|
||||
case InstructionsEnum.blurMeansTranslate:
|
||||
return L10n.of(context)!.blurMeansTranslateTitle;
|
||||
return l10n.blurMeansTranslateTitle;
|
||||
case InstructionsEnum.tooltipInstructions:
|
||||
return L10n.of(context)!.tooltipInstructionsTitle;
|
||||
return l10n.tooltipInstructionsTitle;
|
||||
case InstructionsEnum.clickAgainToDeselect:
|
||||
case InstructionsEnum.speechToText:
|
||||
case InstructionsEnum.l1Translation:
|
||||
|
|
@ -53,46 +44,30 @@ extension InstructionsEnumExtension on InstructionsEnum {
|
|||
}
|
||||
}
|
||||
|
||||
String body(BuildContext context) {
|
||||
if (!context.mounted) {
|
||||
ErrorHandler.logError(
|
||||
e: Exception("Context not mounted"),
|
||||
m: 'InstructionsEnumExtension.body for $this',
|
||||
);
|
||||
debugger(when: kDebugMode);
|
||||
return "";
|
||||
}
|
||||
String body(L10n l10n) {
|
||||
switch (this) {
|
||||
case InstructionsEnum.itInstructions:
|
||||
return L10n.of(context)!.itInstructionsBody;
|
||||
return l10n.itInstructionsBody;
|
||||
case InstructionsEnum.clickMessage:
|
||||
return L10n.of(context)!.clickMessageBody;
|
||||
return l10n.clickMessageBody;
|
||||
case InstructionsEnum.blurMeansTranslate:
|
||||
return L10n.of(context)!.blurMeansTranslateBody;
|
||||
return l10n.blurMeansTranslateBody;
|
||||
case InstructionsEnum.speechToText:
|
||||
return L10n.of(context)!.speechToTextBody;
|
||||
return l10n.speechToTextBody;
|
||||
case InstructionsEnum.l1Translation:
|
||||
return L10n.of(context)!.l1TranslationBody;
|
||||
return l10n.l1TranslationBody;
|
||||
case InstructionsEnum.translationChoices:
|
||||
return L10n.of(context)!.translationChoicesBody;
|
||||
return l10n.translationChoicesBody;
|
||||
case InstructionsEnum.clickAgainToDeselect:
|
||||
return L10n.of(context)!.clickTheWordAgainToDeselect;
|
||||
return l10n.clickTheWordAgainToDeselect;
|
||||
case InstructionsEnum.tooltipInstructions:
|
||||
return PlatformInfos.isMobile
|
||||
? L10n.of(context)!.tooltipInstructionsMobileBody
|
||||
: L10n.of(context)!.tooltipInstructionsBrowserBody;
|
||||
? l10n.tooltipInstructionsMobileBody
|
||||
: l10n.tooltipInstructionsBrowserBody;
|
||||
}
|
||||
}
|
||||
|
||||
bool toggledOff(BuildContext context) {
|
||||
if (!context.mounted) {
|
||||
ErrorHandler.logError(
|
||||
e: Exception("Context not mounted"),
|
||||
m: 'InstructionsEnumExtension.toggledOff for $this',
|
||||
);
|
||||
debugger(when: kDebugMode);
|
||||
return false;
|
||||
}
|
||||
bool toggledOff() {
|
||||
final instructionSettings =
|
||||
MatrixState.pangeaController.userController.profile.instructionSettings;
|
||||
switch (this) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:fluffychat/config/app_config.dart';
|
|||
import 'package:fluffychat/pangea/enum/instructions_enum.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class InlineTooltip extends StatelessWidget {
|
||||
final InstructionsEnum instructionsEnum;
|
||||
|
|
@ -15,7 +16,7 @@ class InlineTooltip extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (instructionsEnum.toggledOff(context)) {
|
||||
if (instructionsEnum.toggledOff()) {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ class InlineTooltip extends StatelessWidget {
|
|||
// Text in the middle
|
||||
Center(
|
||||
child: Text(
|
||||
instructionsEnum.body(context),
|
||||
instructionsEnum.body(L10n.of(context)!),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
height: 1.5,
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class InstructionsController {
|
|||
}
|
||||
_instructionsShown[key.toString()] = true;
|
||||
|
||||
if (key.toggledOff(context)) {
|
||||
if (key.toggledOff()) {
|
||||
return;
|
||||
}
|
||||
if (L10n.of(context) == null) {
|
||||
|
|
@ -94,33 +94,36 @@ class InstructionsController {
|
|||
final botStyle = BotStyle.text(context);
|
||||
Future.delayed(
|
||||
const Duration(seconds: 1),
|
||||
() => OverlayUtil.showPositionedCard(
|
||||
context: context,
|
||||
backDropToDismiss: false,
|
||||
cardToShow: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
CardHeader(
|
||||
text: key.title(context),
|
||||
botExpression: BotExpression.idle,
|
||||
onClose: () => {_instructionsClosed[key.toString()] = true},
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
key.body(context),
|
||||
style: botStyle,
|
||||
() {
|
||||
if (!context.mounted) return;
|
||||
OverlayUtil.showPositionedCard(
|
||||
context: context,
|
||||
backDropToDismiss: false,
|
||||
cardToShow: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
CardHeader(
|
||||
text: key.title(L10n.of(context)!),
|
||||
botExpression: BotExpression.idle,
|
||||
onClose: () => {_instructionsClosed[key.toString()] = true},
|
||||
),
|
||||
),
|
||||
if (showToggle) InstructionsToggle(instructionsKey: key),
|
||||
],
|
||||
),
|
||||
maxHeight: 300,
|
||||
maxWidth: 300,
|
||||
transformTargetId: transformTargetKey,
|
||||
closePrevOverlay: false,
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
key.body(L10n.of(context)!),
|
||||
style: botStyle,
|
||||
),
|
||||
),
|
||||
if (showToggle) InstructionsToggle(instructionsKey: key),
|
||||
],
|
||||
),
|
||||
maxHeight: 300,
|
||||
maxWidth: 300,
|
||||
transformTargetId: transformTargetKey,
|
||||
closePrevOverlay: false,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -152,7 +155,7 @@ class InstructionsToggleState extends State<InstructionsToggle> {
|
|||
return SwitchListTile.adaptive(
|
||||
activeColor: AppConfig.activeToggleColor,
|
||||
title: Text(L10n.of(context)!.doNotShowAgain),
|
||||
value: widget.instructionsKey.toggledOff(context),
|
||||
value: widget.instructionsKey.toggledOff(),
|
||||
onChanged: ((value) async {
|
||||
pangeaController.instructions.setToggledOff(
|
||||
widget.instructionsKey,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue