mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-22 21:03:42 +08:00
更新网页汉化功能
This commit is contained in:
parent
23fed0b7a7
commit
6d914f02da
@ -31,6 +31,10 @@ class WebViewModel {
|
||||
|
||||
bool enableCapture = false;
|
||||
|
||||
Map<String, String>? _curReplaceWords;
|
||||
|
||||
Map<String, String>? get curReplaceWords => _curReplaceWords;
|
||||
|
||||
initWebView({String title = ""}) async {
|
||||
try {
|
||||
webview = await WebviewWindow.create(
|
||||
@ -90,6 +94,12 @@ class WebViewModel {
|
||||
if (url.startsWith(hangar)) {
|
||||
replaceWords.addAll(_getLocalizationResource("hangar"));
|
||||
}
|
||||
|
||||
_curReplaceWords = {};
|
||||
for (var element in replaceWords) {
|
||||
_curReplaceWords?[element["word"] ?? ""] =
|
||||
element["replacement"] ?? "";
|
||||
}
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await webview.evaluateJavaScript(
|
||||
"WebLocalizationUpdateReplaceWords(${json.encode(replaceWords)},$enableCapture)");
|
||||
@ -129,7 +139,7 @@ class WebViewModel {
|
||||
|
||||
/// https://github.com/CxJuice/Uex_Chinese_Translate
|
||||
// get versions
|
||||
const hostUrl = "https://ch.citizenwiki.cn/json-files";
|
||||
const hostUrl = "https://ch.citizenwiki.cn/json-files/locales";
|
||||
|
||||
final v = AppWebLocalizationVersionsData.fromJson(
|
||||
await _getJson("$hostUrl/versions.json"));
|
||||
@ -153,7 +163,7 @@ class WebViewModel {
|
||||
|
||||
List<Map<String, String>> _getLocalizationResource(String key) {
|
||||
final List<Map<String, String>> localizations = [];
|
||||
final dict = localizationResource[key]?["dict"];
|
||||
final dict = localizationResource[key];
|
||||
if (dict is Map) {
|
||||
for (var element in dict.entries) {
|
||||
final k = element.key
|
||||
|
@ -9,7 +9,6 @@ class WebviewLocalizationCaptureUIModel extends BaseUIModel {
|
||||
WebviewLocalizationCaptureUIModel(this.webViewModel);
|
||||
|
||||
Map<String, dynamic> data = {};
|
||||
Map<String, dynamic> oldData = {};
|
||||
|
||||
String renderString = "";
|
||||
|
||||
@ -32,11 +31,13 @@ class WebviewLocalizationCaptureUIModel extends BaseUIModel {
|
||||
if (map["action"] == "webview_localization_capture") {
|
||||
dPrint(
|
||||
"<WebviewLocalizationCaptureUIModel> webview_localization_capture message == $map");
|
||||
if (!oldData.containsKey(map["key"])) {
|
||||
data[map["key"].toString().trim().toLowerCase().replaceAll(" ", "_")] =
|
||||
map["value"];
|
||||
final key = map["key"];
|
||||
if (key != null && key.toString().trim() != "") {
|
||||
if (!(webViewModel.curReplaceWords?.containsKey(key) ?? false)) {
|
||||
data[key] = map["value"];
|
||||
}
|
||||
_updateRenderString();
|
||||
}
|
||||
_updateRenderString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +47,6 @@ class WebviewLocalizationCaptureUIModel extends BaseUIModel {
|
||||
}
|
||||
|
||||
doClean() {
|
||||
oldData.addAll(data);
|
||||
data.clear();
|
||||
_updateRenderString();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ dependencies:
|
||||
markdown_widget: ^2.2.0
|
||||
extended_image: ^8.1.1
|
||||
hyper_thread_downloader: ^1.0.5
|
||||
device_info_plus: ^9.0.3
|
||||
device_info_plus: ^10.0.0
|
||||
file_picker: ^5.5.0
|
||||
file_sizes: ^1.0.6
|
||||
desktop_webview_window: ^0.2.3
|
||||
|
Loading…
Reference in New Issue
Block a user