feat: add message translation support

- 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.
This commit is contained in:
zjs81
2026-04-02 19:09:17 -07:00
parent 82adbd761b
commit 9bf649e2c6
57 changed files with 4879 additions and 184 deletions
+13
View File
@@ -3,6 +3,7 @@ import 'dart:typed_data';
import 'package:meshcore_open/utils/app_logger.dart';
import '../models/channel_message.dart';
import '../models/translation_support.dart';
import '../helpers/smaz.dart';
import 'prefs_manager.dart';
@@ -98,6 +99,11 @@ class ChannelMessageStore {
'senderKey': msg.senderKey != null ? base64Encode(msg.senderKey!) : null,
'senderName': msg.senderName,
'text': msg.text,
'originalText': msg.originalText,
'translatedText': msg.translatedText,
'translatedLanguageCode': msg.translatedLanguageCode,
'translationStatus': msg.translationStatus.value,
'translationModelId': msg.translationModelId,
'timestamp': msg.timestamp.millisecondsSinceEpoch,
'isOutgoing': msg.isOutgoing,
'status': msg.status.index,
@@ -126,6 +132,13 @@ class ChannelMessageStore {
: null,
senderName: json['senderName'] as String,
text: decodedText,
originalText: json['originalText'] as String?,
translatedText: json['translatedText'] as String?,
translatedLanguageCode: json['translatedLanguageCode'] as String?,
translationStatus: parseMessageTranslationStatus(
json['translationStatus'],
),
translationModelId: json['translationModelId'] as String?,
timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp'] as int),
isOutgoing: json['isOutgoing'] as bool,
status: ChannelMessageStatus.values[json['status'] as int],
+13
View File
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:typed_data';
import '../models/message.dart';
import '../models/translation_support.dart';
import '../helpers/smaz.dart';
import '../utils/app_logger.dart';
import 'prefs_manager.dart';
@@ -83,6 +84,11 @@ class MessageStore {
'isCli': msg.isCli,
'status': msg.status.index,
'messageId': msg.messageId,
'originalText': msg.originalText,
'translatedText': msg.translatedText,
'translatedLanguageCode': msg.translatedLanguageCode,
'translationStatus': msg.translationStatus.value,
'translationModelId': msg.translationModelId,
'retryCount': msg.retryCount,
'estimatedTimeoutMs': msg.estimatedTimeoutMs,
'expectedAckHash': msg.expectedAckHash,
@@ -115,6 +121,13 @@ class MessageStore {
isCli: isCli,
status: MessageStatus.values[json['status'] as int],
messageId: json['messageId'] as String?,
originalText: json['originalText'] as String?,
translatedText: json['translatedText'] as String?,
translatedLanguageCode: json['translatedLanguageCode'] as String?,
translationStatus: parseMessageTranslationStatus(
json['translationStatus'],
),
translationModelId: json['translationModelId'] as String?,
retryCount: json['retryCount'] as int? ?? 0,
estimatedTimeoutMs: json['estimatedTimeoutMs'] as int?,
expectedAckHash: json['expectedAckHash'] as int? ?? 0,