mirror of
https://github.com/StarCitizenToolBox/app.git
synced 2026-01-13 19:50:28 +00:00
feat: remove Google Translate functionality and related UI elements
This commit is contained in:
parent
c2a512699c
commit
6c940ce6f3
@ -98,23 +98,6 @@ class Api {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> doGoogleTranslate(String input) async {
|
|
||||||
final out = await RSHttp.getText(
|
|
||||||
"${URLConf.googleTranslateApiUrl}/translate_a/single?client=gtx&dt=t&sl=auto&tl=en&q=${Uri.encodeComponent(input)}");
|
|
||||||
// [[["Hello","你好",null,null,10]],null,"zh-CN",null,null,null,1,[],[["zh-CN"],null,[1],["zh-CN"]]]
|
|
||||||
final list = json.decode(out);
|
|
||||||
if (list is List && list.isNotEmpty) {
|
|
||||||
final data = list.first;
|
|
||||||
if (data is List && data.isNotEmpty) {
|
|
||||||
final text = data.first;
|
|
||||||
if (text is List && text.isNotEmpty) {
|
|
||||||
return text.first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<bool> isUseInternalDNS() async {
|
static Future<bool> isUseInternalDNS() async {
|
||||||
final userBox = await Hive.openBox("app_conf");
|
final userBox = await Hive.openBox("app_conf");
|
||||||
final isUseInternalDNS =
|
final isUseInternalDNS =
|
||||||
|
|||||||
@ -25,8 +25,6 @@ class URLConf {
|
|||||||
|
|
||||||
static String get webTranslateHomeUrl => "$gitApiHome/SCToolBox/ScWeb_Chinese_Translate/raw/branch/main/json/locales";
|
static String get webTranslateHomeUrl => "$gitApiHome/SCToolBox/ScWeb_Chinese_Translate/raw/branch/main/json/locales";
|
||||||
|
|
||||||
static const String googleTranslateApiUrl = "https://translate-g-proxy.xkeyc.com";
|
|
||||||
|
|
||||||
static const feedbackUrl = "https://support.citizenwiki.cn/all";
|
static const feedbackUrl = "https://support.citizenwiki.cn/all";
|
||||||
static const feedbackFAQUrl = "https://support.citizenwiki.cn/t/sc-toolbox";
|
static const feedbackFAQUrl = "https://support.citizenwiki.cn/t/sc-toolbox";
|
||||||
static String nav42KitUrl =
|
static String nav42KitUrl =
|
||||||
|
|||||||
@ -74,7 +74,6 @@ class InputMethodDialogUI extends HookConsumerWidget {
|
|||||||
final text = model.onTextChange("src", str);
|
final text = model.onTextChange("src", str);
|
||||||
destTextCtrl.text = text ?? "";
|
destTextCtrl.text = text ?? "";
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
model.checkAutoTranslate();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -113,18 +112,6 @@ class InputMethodDialogUI extends HookConsumerWidget {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(S.current.input_method_auto_translate),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
ToggleSwitch(
|
|
||||||
checked: state.isEnableAutoTranslate,
|
|
||||||
onChanged: (b) =>
|
|
||||||
_onSwitchAutoTranslate(context, model, b),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(width: 24),
|
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text(S.current.input_method_remote_input_service),
|
Text(S.current.input_method_remote_input_service),
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import 'package:flutter/widgets.dart';
|
|||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
import 'package:hive_ce/hive.dart';
|
import 'package:hive_ce/hive.dart';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
import 'package:starcitizen_doctor/api/api.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||||
import 'package:starcitizen_doctor/ui/home/localization/localization_ui_model.dart';
|
import 'package:starcitizen_doctor/ui/home/localization/localization_ui_model.dart';
|
||||||
|
|
||||||
@ -40,14 +39,12 @@ class InputMethodDialogUIModel extends _$InputMethodDialogUIModel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!skipUpdate) await localizationModel.checkCommunityInputMethodUpdate();
|
if (!skipUpdate) await localizationModel.checkCommunityInputMethodUpdate();
|
||||||
final keyMaps =
|
final keyMaps = await localizationModel.getCommunityInputMethodSupportData();
|
||||||
await localizationModel.getCommunityInputMethodSupportData();
|
|
||||||
dPrint("[InputMethodDialogUIModel] keyMapsLen: ${keyMaps?.length}");
|
dPrint("[InputMethodDialogUIModel] keyMapsLen: ${keyMaps?.length}");
|
||||||
final worldMaps = keyMaps?.map((key, value) => MapEntry(value.trim(), key));
|
final worldMaps = keyMaps?.map((key, value) => MapEntry(value.trim(), key));
|
||||||
final appBox = await Hive.openBox("app_conf");
|
final appBox = await Hive.openBox("app_conf");
|
||||||
final enableAutoCopy = appBox.get("enableAutoCopy", defaultValue: false);
|
final enableAutoCopy = appBox.get("enableAutoCopy", defaultValue: false);
|
||||||
final isEnableAutoTranslate =
|
final isEnableAutoTranslate = appBox.get("isEnableAutoTranslate", defaultValue: false);
|
||||||
appBox.get("isEnableAutoTranslate", defaultValue: false);
|
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
keyMaps: keyMaps,
|
keyMaps: keyMaps,
|
||||||
worldMaps: worldMaps,
|
worldMaps: worldMaps,
|
||||||
@ -127,22 +124,16 @@ class InputMethodDialogUIModel extends _$InputMethodDialogUIModel {
|
|||||||
TextEditingController? _srcTextCtrl;
|
TextEditingController? _srcTextCtrl;
|
||||||
TextEditingController? _destTextCtrl;
|
TextEditingController? _destTextCtrl;
|
||||||
|
|
||||||
void setUpController(
|
void setUpController(TextEditingController srcTextCtrl, TextEditingController destTextCtrl) {
|
||||||
TextEditingController srcTextCtrl, TextEditingController destTextCtrl) {
|
|
||||||
_srcTextCtrl = srcTextCtrl;
|
_srcTextCtrl = srcTextCtrl;
|
||||||
_destTextCtrl = destTextCtrl;
|
_destTextCtrl = destTextCtrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onSendText(
|
Future<void> onSendText(String text, {bool autoCopy = false, bool autoInput = false}) async {
|
||||||
String text, {
|
|
||||||
bool autoCopy = false,
|
|
||||||
bool autoInput = false,
|
|
||||||
}) async {
|
|
||||||
debugPrint("[InputMethodDialogUIState] onSendText: $text");
|
debugPrint("[InputMethodDialogUIState] onSendText: $text");
|
||||||
_srcTextCtrl?.text = text;
|
_srcTextCtrl?.text = text;
|
||||||
_destTextCtrl?.text = onTextChange("src", text) ?? "";
|
_destTextCtrl?.text = onTextChange("src", text) ?? "";
|
||||||
if (_destTextCtrl?.text.isEmpty ?? true) return;
|
if (_destTextCtrl?.text.isEmpty ?? true) return;
|
||||||
checkAutoTranslate(webMessage: true);
|
|
||||||
if (autoCopy && !state.isAutoTranslateWorking) {
|
if (autoCopy && !state.isAutoTranslateWorking) {
|
||||||
Clipboard.setData(ClipboardData(text: _destTextCtrl?.text ?? ""));
|
Clipboard.setData(ClipboardData(text: _destTextCtrl?.text ?? ""));
|
||||||
}
|
}
|
||||||
@ -153,39 +144,4 @@ class InputMethodDialogUIModel extends _$InputMethodDialogUIModel {
|
|||||||
final appConf = await Hive.openBox("app_conf");
|
final appConf = await Hive.openBox("app_conf");
|
||||||
await appConf.put("isEnableAutoTranslate", b);
|
await appConf.put("isEnableAutoTranslate", b);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer? _translateTimer;
|
|
||||||
|
|
||||||
Future<void> checkAutoTranslate({bool webMessage = false}) async {
|
|
||||||
final sourceText = _srcTextCtrl?.text ?? "";
|
|
||||||
final content = _destTextCtrl?.text ?? "";
|
|
||||||
if (sourceText.trim().isEmpty) return;
|
|
||||||
if (state.isEnableAutoTranslate) {
|
|
||||||
if (_translateTimer != null) _translateTimer?.cancel();
|
|
||||||
state = state.copyWith(isAutoTranslateWorking: true);
|
|
||||||
_translateTimer =
|
|
||||||
Timer(Duration(milliseconds: webMessage ? 1 : 400), () async {
|
|
||||||
try {
|
|
||||||
final inputText = sourceText.replaceAll("\n", " ");
|
|
||||||
final r = await Api.doGoogleTranslate(inputText);
|
|
||||||
if (r != null) {
|
|
||||||
String resultText = r;
|
|
||||||
// resultText 首字母大写
|
|
||||||
if (content.isNotEmpty) {
|
|
||||||
final firstChar = resultText.characters.first;
|
|
||||||
resultText =
|
|
||||||
resultText.replaceFirst(firstChar, firstChar.toUpperCase());
|
|
||||||
}
|
|
||||||
_destTextCtrl?.text = "$content \n[en] $resultText";
|
|
||||||
if (state.enableAutoCopy || webMessage) {
|
|
||||||
Clipboard.setData(ClipboardData(text: _destTextCtrl?.text ?? ""));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("[InputMethodDialogUIModel] AutoTranslate error: $e");
|
|
||||||
}
|
|
||||||
state = state.copyWith(isAutoTranslateWorking: false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user