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