mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
- Introduced translation functionality in chat screen, allowing users to translate messages before sending. - Added MessageTranslationButton to the input bar for enabling/disabling translation. - Implemented translation service to handle incoming and outgoing text translations using llama models. - Enhanced message storage to include original and translated text, language codes, and translation status. - Created UI components for displaying translated messages and managing translation options. - Added translation model management, including downloading and storing models locally. - Updated app settings to manage translation preferences and model selections.
61 lines
1.7 KiB
Dart
61 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../helpers/link_handler.dart';
|
|
|
|
class TranslatedMessageContent extends StatelessWidget {
|
|
final String displayText;
|
|
final String? originalText;
|
|
final TextStyle style;
|
|
final TextStyle? originalStyle;
|
|
final bool showOriginalFirst;
|
|
|
|
const TranslatedMessageContent({
|
|
super.key,
|
|
required this.displayText,
|
|
required this.style,
|
|
this.originalText,
|
|
this.originalStyle,
|
|
this.showOriginalFirst = true,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final trimmedDisplay = displayText.trim();
|
|
final trimmedOriginal = originalText?.trim();
|
|
final shouldShowOriginal =
|
|
trimmedOriginal != null &&
|
|
trimmedOriginal.isNotEmpty &&
|
|
trimmedOriginal != trimmedDisplay;
|
|
final originalWidget = shouldShowOriginal
|
|
? LinkHandler.buildLinkifyText(
|
|
context: context,
|
|
text: trimmedOriginal,
|
|
style:
|
|
originalStyle ??
|
|
style.copyWith(
|
|
fontStyle: FontStyle.italic,
|
|
fontSize: style.fontSize,
|
|
),
|
|
)
|
|
: null;
|
|
final translatedWidget = LinkHandler.buildLinkifyText(
|
|
context: context,
|
|
text: trimmedDisplay,
|
|
style: style,
|
|
);
|
|
|
|
if (!shouldShowOriginal) {
|
|
return translatedWidget;
|
|
}
|
|
|
|
final children = showOriginalFirst
|
|
? [originalWidget!, const SizedBox(height: 6), translatedWidget]
|
|
: [translatedWidget, const SizedBox(height: 6), originalWidget!];
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: children,
|
|
);
|
|
}
|
|
}
|