From 57c912f919a2a7847ed87bafcf37beb16524443b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Wed, 7 Aug 2024 00:18:10 +0800 Subject: [PATCH] regex --- .../LunaTranslator/gui/dialog_savedgame.py | 17 +- .../LunaTranslator/gui/inputdialog.py | 149 ++++++------------ .../LunaTranslator/gui/setting_transopti.py | 18 ++- .../LunaTranslator/gui/setting_tts.py | 2 +- .../LunaTranslator/gui/usefulwidget.py | 36 ++++- .../LunaTranslator/metadata/abstract.py | 22 ++- .../LunaTranslator/metadata/bangumi.py | 1 - .../LunaTranslator/metadata/dlsite.py | 1 - .../LunaTranslator/metadata/fanza.py | 1 - .../LunaTranslator/metadata/steam.py | 1 - .../LunaTranslator/myutils/config.py | 137 +++++++++++++++- LunaTranslator/LunaTranslator/myutils/post.py | 8 +- .../LunaTranslator/myutils/utils.py | 37 +++-- .../LunaTranslator/transoptimi/noundict.py | 65 +------- .../transoptimi/transerrorfix.py | 4 +- .../LunaTranslator/transoptimi/vndbnamemap.py | 34 ++-- .../files/defaultconfig/config.json | 2 +- .../defaultconfig/postprocessconfig.json | 13 +- LunaTranslator/files/lang/ar.json | 5 +- LunaTranslator/files/lang/cht.json | 5 +- LunaTranslator/files/lang/cs.json | 5 +- LunaTranslator/files/lang/de.json | 5 +- LunaTranslator/files/lang/en.json | 5 +- LunaTranslator/files/lang/es.json | 5 +- LunaTranslator/files/lang/fr.json | 5 +- LunaTranslator/files/lang/it.json | 5 +- LunaTranslator/files/lang/ja.json | 5 +- LunaTranslator/files/lang/ko.json | 5 +- LunaTranslator/files/lang/nl.json | 5 +- LunaTranslator/files/lang/pl.json | 5 +- LunaTranslator/files/lang/pt.json | 5 +- LunaTranslator/files/lang/ru.json | 5 +- LunaTranslator/files/lang/sv.json | 5 +- LunaTranslator/files/lang/th.json | 5 +- LunaTranslator/files/lang/tr.json | 5 +- LunaTranslator/files/lang/uk.json | 5 +- LunaTranslator/files/lang/vi.json | 5 +- LunaTranslator/files/lang/zh.json | 5 +- docs/zh/textprocess.md | 22 ++- docs/zh/transoptimi.md | 2 +- plugins/CMakeLists.txt | 4 +- 41 files changed, 425 insertions(+), 251 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index 6c31a971..bf0c367e 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -42,6 +42,7 @@ from gui.codeacceptdialog import codeacceptdialog from gui.inputdialog import ( noundictconfigdialog1, yuyinzhidingsetting, + postconfigdialog2x, autoinitdialog, autoinitdialog_items, postconfigdialog, @@ -591,7 +592,19 @@ def maybehavebutton(self, gameuid, post): icon="fa.gear", callback=lambda: codeacceptdialog(self) ) elif "args" in postprocessconfig[post]: - if isinstance(list(postprocessconfig[post]["args"].values())[0], dict): + if post == "stringreplace": + callback = functools.partial( + postconfigdialog2x, + self, + savehook_new_data[gameuid]["save_text_process_info"][ + "postprocessconfig" + ][post]["args"]["internal"], + savehook_new_data[gameuid]["save_text_process_info"][ + "postprocessconfig" + ][post]["name"], + ["正则", "转义", "原文内容", "替换为"], + ) + elif isinstance(list(postprocessconfig[post]["args"].values())[0], dict): callback = functools.partial( postconfigdialog, self, @@ -1081,7 +1094,7 @@ class dialog_setting_game_internal(QWidget): self, savehook_new_data[gameuid]["tts_repair_regex"], "语音修正", - ["正则", "原文", "替换"], + ["正则", "转义", "原文", "替换"], ), icon="fa.gear", ), diff --git a/LunaTranslator/LunaTranslator/gui/inputdialog.py b/LunaTranslator/LunaTranslator/gui/inputdialog.py index c5e83a8a..fa22cc73 100644 --- a/LunaTranslator/LunaTranslator/gui/inputdialog.py +++ b/LunaTranslator/LunaTranslator/gui/inputdialog.py @@ -36,40 +36,22 @@ class noundictconfigdialog1(LDialog): self.model.insertRow( row, [ + QStandardItem(), QStandardItem(), QStandardItem(item["key"]), QStandardItem(item["value"]), ], ) + if "regex" not in item: + item["regex"] = False + if "escape" not in item: + item["escape"] = item["regex"] self.table.setIndexWidget( self.model.index(row, 0), getsimpleswitch(item, "regex") ) - - def showmenu(self, table: TableViewW, _): - r = table.currentIndex().row() - if r < 0: - return - menu = QMenu(table) - up = LAction("上移") - down = LAction("下移") - copy = LAction("复制") - paste = LAction("粘贴") - menu.addAction(up) - menu.addAction(down) - menu.addAction(copy) - menu.addAction(paste) - action = menu.exec(table.cursor().pos()) - - if action == up: - table.moverank(-1) - - elif action == down: - table.moverank(1) - elif action == copy: - table.copytable() - - elif action == paste: - table.pastetable() + self.table.setIndexWidget( + self.model.index(row, 1), getsimpleswitch(item, "escape") + ) def __init__(self, parent, reflist, title, label) -> None: super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) @@ -82,15 +64,15 @@ class noundictconfigdialog1(LDialog): self.model.setHorizontalHeaderLabels(label) table = TableViewW(self) table.setModel(self.model) + table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch) table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch) - table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch) + table.horizontalHeader().setSectionResizeMode( + 1, QHeaderView.ResizeMode.ResizeToContents + ) table.horizontalHeader().setSectionResizeMode( 0, QHeaderView.ResizeMode.ResizeToContents ) - table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) - table.customContextMenuRequested.connect( - functools.partial(self.showmenu, table) - ) + table.setsimplemenu() self.table = table for row, item in enumerate(reflist): @@ -141,18 +123,39 @@ class noundictconfigdialog1(LDialog): def __setindexwidget(self, index: QModelIndex, data): if index.column() == 0: self.table.setIndexWidget(index, getsimpleswitch(data, "regex")) + if index.column() == 1: + self.table.setIndexWidget(index, getsimpleswitch(data, "escape")) def __getindexwidgetdata(self, index: QModelIndex): - return {"regex": self.table.indexWidgetX(index).isChecked()} + if index.column() == 0: + return {"regex": self.table.indexWidgetX(index).isChecked()} + if index.column() == 1: + return {"escape": self.table.indexWidgetX(index).isChecked()} def apply(self): - self.table.dedumpmodel(1) + def __check(row): + k = self.model.item(row, 2).text() + if k == "": + return "" + switch = self.table.indexWidgetX(row, 0).isChecked() + es = self.table.indexWidgetX(row, 1).isChecked() + return (switch, es, k) + + self.table.dedumpmodel(__check) self.reflist.clear() for row in range(self.model.rowCount()): - k = self.model.item(row, 1).text() - v = self.model.item(row, 2).text() + k = self.model.item(row, 2).text() + v = self.model.item(row, 3).text() switch = self.table.indexWidgetX(row, 0) - self.reflist.append({"key": k, "value": v, "regex": switch.isChecked()}) + es = self.table.indexWidgetX(row, 1) + self.reflist.append( + { + "key": k, + "value": v, + "escape": es.isChecked(), + "regex": switch.isChecked(), + } + ) def closeEvent(self, a0: QCloseEvent) -> None: self.button.setFocus() @@ -261,24 +264,6 @@ class yuyinzhidingsetting(LDialog): self.table.setIndexWidget(self.model.index(row, 1), com) self.table.setIndexWidget(self.model.index(row, 3), self.createacombox(item)) - def showmenu(self, table: TableViewW, _): - r = table.currentIndex().row() - if r < 0: - return - menu = QMenu(table) - up = LAction("上移") - down = LAction("下移") - menu.addAction(up) - menu.addAction(down) - action = menu.exec(table.cursor().pos()) - - if action == up: - - table.moverank(-1) - - elif action == down: - table.moverank(1) - def createacombox(self, config): com = LFocusCombo() com.addItems(["跳过", "默认", "选择声音"]) @@ -348,10 +333,7 @@ class yuyinzhidingsetting(LDialog): table.horizontalHeader().setSectionResizeMode( 0, QHeaderView.ResizeMode.ResizeToContents ) - table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) - table.customContextMenuRequested.connect( - functools.partial(self.showmenu, table) - ) + table.setsimplemenu({"copypaste": False}) self.table = table for row, item in enumerate(reflist): @@ -695,38 +677,8 @@ class multicolorset(LDialog): @Singleton_close class postconfigdialog_(LDialog): def closeEvent(self, a0: QCloseEvent) -> None: - if self.closeevent: - self.button.setFocus() - self.apply() - if self.closecallback: - self.closecallback() - - def showmenu(self, table: TableViewW, pos): - r = table.currentIndex().row() - if r < 0: - return - menu = QMenu(table) - up = LAction("上移") - down = LAction("下移") - copy = LAction("复制") - paste = LAction("粘贴") - menu.addAction(up) - menu.addAction(down) - menu.addAction(copy) - menu.addAction(paste) - action = menu.exec(table.cursor().pos()) - - if action == up: - - table.moverank(-1) - - elif action == down: - table.moverank(1) - elif action == copy: - table.copytable() - - elif action == paste: - table.pastetable() + self.button.setFocus() + self.apply() def apply(self): self.table.dedumpmodel(0) @@ -747,14 +699,9 @@ class postconfigdialog_(LDialog): else: raise - def __init__( - self, parent, configdict, title, headers, closecallback=None, dictkeys=None - ) -> None: + def __init__(self, parent, configdict, title, headers, dictkeys=None) -> None: super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) - self.closecallback = closecallback self.setWindowTitle(title) - # self.setWindowModality(Qt.ApplicationModal) - self.closeevent = False formLayout = QVBoxLayout(self) # 配置layout self.dictkeys = dictkeys model = LStandardItemModel(len(configdict), 1, self) @@ -781,10 +728,7 @@ class postconfigdialog_(LDialog): table.setModel(model) table.setWordWrap(False) table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) - table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) - table.customContextMenuRequested.connect( - functools.partial(self.showmenu, table) - ) + table.setsimplemenu() button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"]) self.table = table button.btn1clicked.connect(table.insertplainrow) @@ -796,7 +740,6 @@ class postconfigdialog_(LDialog): self.button = button self.model = model self.configdict = configdict - self.closeevent = True search = QHBoxLayout() searchcontent = QLineEdit() search.addWidget(searchcontent) @@ -827,3 +770,7 @@ class postconfigdialog_(LDialog): def postconfigdialog(parent, configdict, title, header): postconfigdialog_(parent, configdict, title, header) + + +def postconfigdialog2x(parent, reflist, title, header): + noundictconfigdialog1(parent, reflist, title, header) diff --git a/LunaTranslator/LunaTranslator/gui/setting_transopti.py b/LunaTranslator/LunaTranslator/gui/setting_transopti.py index a25321e7..2bea0421 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_transopti.py +++ b/LunaTranslator/LunaTranslator/gui/setting_transopti.py @@ -16,7 +16,12 @@ from gui.usefulwidget import ( getvboxwidget, makesubtab_lazy, ) -from gui.inputdialog import postconfigdialog, autoinitdialog, autoinitdialog_items +from gui.inputdialog import ( + postconfigdialog, + autoinitdialog, + autoinitdialog_items, + postconfigdialog2x, +) def delaysetcomparetext(self, s): @@ -101,7 +106,16 @@ def setTab7_lazy(self, basel): callback=lambda: codeacceptdialog(self), ) elif "args" in postprocessconfig[post]: - if isinstance(list(postprocessconfig[post]["args"].values())[0], dict): + + if post=='stringreplace': + callback = functools.partial( + postconfigdialog2x, + self, + postprocessconfig[post]["args"]['internal'], + postprocessconfig[post]["name"], + ["正则", "转义", "原文内容", "替换为"], + ) + elif isinstance(list(postprocessconfig[post]["args"].values())[0], dict): callback = functools.partial( postconfigdialog, self, diff --git a/LunaTranslator/LunaTranslator/gui/setting_tts.py b/LunaTranslator/LunaTranslator/gui/setting_tts.py index 5fcd3e11..852c3d69 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_tts.py +++ b/LunaTranslator/LunaTranslator/gui/setting_tts.py @@ -234,7 +234,7 @@ def setTab5lz(self): self, globalconfig["ttscommon"]["tts_repair_regex"], "语音修正", - ["正则", "原文", "替换"], + ["正则",'转义', "原文", "替换"], ), icon="fa.gear", ), diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 98908069..38c9d124 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -95,6 +95,36 @@ class TableViewW(QTableView): super().__init__(*argc) self.setSelectionMode(QAbstractItemView.SelectionMode.ContiguousSelection) + def showmenu(self, info, pos): + r = self.currentIndex().row() + if r < 0: + return + menu = QMenu(self) + up = LAction("上移") + down = LAction("下移") + copy = LAction("复制") + paste = LAction("粘贴") + menu.addAction(up) + menu.addAction(down) + if info.get("copypaste", True): + menu.addAction(copy) + menu.addAction(paste) + action = menu.exec(self.cursor().pos()) + if action == up: + self.moverank(-1) + elif action == down: + self.moverank(1) + elif action == copy: + self.copytable() + elif action == paste: + self.pastetable() + + def setsimplemenu(self, info=None): + self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) + if info is None: + info = {} + self.customContextMenuRequested.connect(functools.partial(self.showmenu, info)) + def insertplainrow(self, row=0): self.model().insertRow( row, [QStandardItem() for _ in range(self.model().columnCount())] @@ -106,11 +136,15 @@ class TableViewW(QTableView): dedump = set() needremoves = [] for row in range(rows): - k = self.safetext(row, col) + if isinstance(col, int): + k = self.safetext(row, col) + elif callable(col): + k = col(row) if k == "" or k in dedump: needremoves.append(row) continue dedump.add(k) + for row in reversed(needremoves): self.model().removeRow(row) diff --git a/LunaTranslator/LunaTranslator/metadata/abstract.py b/LunaTranslator/LunaTranslator/metadata/abstract.py index ef6643ea..063e519d 100644 --- a/LunaTranslator/LunaTranslator/metadata/abstract.py +++ b/LunaTranslator/LunaTranslator/metadata/abstract.py @@ -2,7 +2,7 @@ import os, hashlib, queue, gobject from myutils.proxy import getproxy from threading import Thread from myutils.commonbase import proxysession -from myutils.config import globalconfig, savehook_new_data +from myutils.config import globalconfig, savehook_new_data, namemapcast from traceback import print_exc from requests import RequestException @@ -176,11 +176,21 @@ class common: if _url not in _urls: savehook_new_data[gameuid]["relationlinks"].append((_vis, _url)) if namemap: - if (len(savehook_new_data[gameuid]["namemap"]) == 0) or ( - not savehook_new_data[gameuid]["vndbnamemap_modified"] - ): - savehook_new_data[gameuid]["namemap"] = namemap - savehook_new_data[gameuid]["vndbnamemap_modified"] = False + dedump = set() + for _ in savehook_new_data[gameuid]["namemap2"]: + dedump.add(_.get("key", "")) + namemap = namemapcast(namemap) + for name in namemap: + if name in dedump: + continue + savehook_new_data[gameuid]["namemap2"].append( + { + "key": name, + "value": namemap[name], + "regex": False, + "escape": False, + } + ) for _ in webtags: if _ in savehook_new_data[gameuid]["webtags"]: diff --git a/LunaTranslator/LunaTranslator/metadata/bangumi.py b/LunaTranslator/LunaTranslator/metadata/bangumi.py index 45a8f5c7..d9c2e897 100644 --- a/LunaTranslator/LunaTranslator/metadata/bangumi.py +++ b/LunaTranslator/LunaTranslator/metadata/bangumi.py @@ -210,7 +210,6 @@ class searcher(common): elif isinstance(__, dict): developers.append(__["v"]) return { - # "namemap": namemap, "title": response["name"], "imagepath_all": [imagepath], "webtags": vndbtags, diff --git a/LunaTranslator/LunaTranslator/metadata/dlsite.py b/LunaTranslator/LunaTranslator/metadata/dlsite.py index d0fef5ed..ed53d2c3 100644 --- a/LunaTranslator/LunaTranslator/metadata/dlsite.py +++ b/LunaTranslator/LunaTranslator/metadata/dlsite.py @@ -113,7 +113,6 @@ class searcher(common): print(imags1) return { - # "namemap": namemap, "title": title, "imagepath_all": [self.dispatchdownloadtask(_) for _ in imags1 + imags2], "webtags": tags, diff --git a/LunaTranslator/LunaTranslator/metadata/fanza.py b/LunaTranslator/LunaTranslator/metadata/fanza.py index 033df093..46ed0e51 100644 --- a/LunaTranslator/LunaTranslator/metadata/fanza.py +++ b/LunaTranslator/LunaTranslator/metadata/fanza.py @@ -171,7 +171,6 @@ class searcher(common): inner = simplehtmlparser(response.text, "div", '
1: + for i in range(len(spja)): + if len(spja[i]) >= 2: + bettermap[spja[i]] = spen[i] + return bettermap + + def tryreadconfig(path, default=None): path = os.path.join("userconfig", path) try: @@ -165,9 +178,9 @@ def getdefaultsavehook(title=None): "gptpromptdict_use": False, "gptpromptdict_merge": False, "gptpromptdict": [], - "vndbnamemap_modified": False, # 元数据 - "namemap": {}, # 人名翻译映射,vndb独占,用于优化翻译 + "namemap2": [], + # "namemap": {}, # 人名翻译映射,vndb独占,用于优化翻译 # # "vid": 0, # "bgmsid": 0, @@ -187,6 +200,11 @@ def getdefaultsavehook(title=None): return default +needcast = False +if "xxxcast" not in globalconfig: + globalconfig["xxxcast"] = True + needcast = True + # fmt: off oldlanguage = ["zh","ja","en","ru","es","ko","fr","cht","vi","tr","pl","uk","it","ar","th","bo","de","sv","nl"] # fmt: on @@ -212,6 +230,14 @@ for gameconfig in savehook_new_data.values(): if ("private_srclang" in gameconfig) and ("private_srclang_2" not in gameconfig): gameconfig["private_srclang_2"] = oldlanguage[gameconfig["private_srclang"]] gameconfig["private_tgtlang_2"] = oldlanguage[gameconfig["private_tgtlang"]] + + if "namemap" in gameconfig: + gameconfig["namemap2"] = [] + for k, v in namemapcast(gameconfig.pop("namemap")).items(): + gameconfig["namemap2"].append( + {"key": k, "value": v, "regex": False, "escape": False} + ) + for __k, __v in _dfsavehook.items(): if __k not in gameconfig: if isinstance(__v, (list, dict)): @@ -221,6 +247,84 @@ for gameconfig in savehook_new_data.values(): if not gameconfig.get("leuse", True): gameconfig.pop("leuse") gameconfig["launch_method"] = "direct" + if needcast: + if "save_text_process_info" not in gameconfig: + continue + if "rank" not in gameconfig["save_text_process_info"]: + continue + if "postprocessconfig" not in gameconfig["save_text_process_info"]: + continue + items = [] + try: + ifuse = False + for post in gameconfig["save_text_process_info"]["rank"]: + # 简单 + if post == "_7": + ifuse = ( + ifuse + or gameconfig["save_text_process_info"]["postprocessconfig"][ + "_7" + ]["use"] + ) + gameconfig["save_text_process_info"]["postprocessconfig"]["_7"][ + "use" + ] = False + for k, v in gameconfig["save_text_process_info"][ + "postprocessconfig" + ]["_7"]["args"]["替换内容"].items(): + items.append( + {"regex": False, "escape": False, "key": k, "value": v} + ) + if post == "_7_zhuanyi": + ifuse = ( + ifuse + or gameconfig["save_text_process_info"]["postprocessconfig"][ + "_7_zhuanyi" + ]["use"] + ) + gameconfig["save_text_process_info"]["postprocessconfig"][ + "_7_zhuanyi" + ]["use"] = False + for k, v in gameconfig["save_text_process_info"][ + "postprocessconfig" + ]["_7_zhuanyi"]["args"]["替换内容"].items(): + items.append( + {"regex": False, "escape": True, "key": k, "value": v} + ) + # 正则 + if post == "_8": + ifuse = ( + ifuse + or gameconfig["save_text_process_info"]["postprocessconfig"][ + "_8" + ]["use"] + ) + gameconfig["save_text_process_info"]["postprocessconfig"]["_8"][ + "use" + ] = False + for k, v in gameconfig["save_text_process_info"][ + "postprocessconfig" + ]["_8"]["args"]["替换内容"].items(): + items.append( + {"regex": True, "escape": True, "key": k, "value": v} + ) + if len(items): + gameconfig["save_text_process_info"]["rank"].append("stringreplace") + gameconfig["save_text_process_info"]["postprocessconfig"][ + "stringreplace" + ] = { + "args": {"internal": items}, + "use": ifuse, + "name": "字符串替换", + } + except: + print_exc() +if "global_namemap" in globalconfig: + globalconfig["global_namemap2"] = [] + for k, v in namemapcast(globalconfig.pop("global_namemap")).items(): + globalconfig["global_namemap2"].append( + {"key": k, "value": v, "regex": False, "escape": False} + ) class __uid2gamepath: @@ -325,6 +429,35 @@ if ocrerrorfix == {}: ocrerrorfix = ocrerrorfixdefault syncconfig(postprocessconfig, defaultpost, True, 3) + +if needcast: + ifuse = False + for post in globalconfig["postprocess_rank"]: + # 简单 + if post == "_7": + ifuse = ifuse or postprocessconfig["_7"]["use"] + postprocessconfig["_7"]["use"] = False + for k, v in postprocessconfig["_7"]["args"]["替换内容"].items(): + postprocessconfig["stringreplace"]["args"]["internal"].append( + {"regex": False, "escape": False, "key": k, "value": v} + ) + if post == "_7_zhuanyi": + ifuse = ifuse or postprocessconfig["_7_zhuanyi"]["use"] + postprocessconfig["_7_zhuanyi"]["use"] = False + for k, v in postprocessconfig["_7_zhuanyi"]["args"]["替换内容"].items(): + postprocessconfig["stringreplace"]["args"]["internal"].append( + {"regex": False, "escape": True, "key": k, "value": v} + ) + # 正则 + if post == "_8": + ifuse = ifuse or postprocessconfig["_8"]["use"] + postprocessconfig["_8"]["use"] = False + for k, v in postprocessconfig["_8"]["args"]["替换内容"].items(): + postprocessconfig["stringreplace"]["args"]["internal"].append( + {"regex": True, "escape": True, "key": k, "value": v} + ) + postprocessconfig["stringreplace"]["use"] = ifuse + for key in defaultglobalconfig["toolbutton"]["buttons"]: if key not in globalconfig["toolbutton"]["rank2"]: globalconfig["toolbutton"]["rank2"].append(key) diff --git a/LunaTranslator/LunaTranslator/myutils/post.py b/LunaTranslator/LunaTranslator/myutils/post.py index 33717d96..7c91bf7a 100644 --- a/LunaTranslator/LunaTranslator/myutils/post.py +++ b/LunaTranslator/LunaTranslator/myutils/post.py @@ -2,7 +2,7 @@ import re, codecs, inspect from traceback import print_exc from collections import Counter import gobject -from myutils.utils import checkchaos, checkmd5reloadmodule, LRUCache, getlangsrc +from myutils.utils import checkchaos, checkmd5reloadmodule, LRUCache, getlangsrc, parsemayberegexreplace from myutils.config import ( postprocessconfig, globalconfig, @@ -219,6 +219,11 @@ def _92_f(line): return line +def stringreplace(line, args): + filters = args["internal"] + return parsemayberegexreplace(filters, line) + + def _7_zhuanyi_f(line, args): filters = args["替换内容"] for fil in filters: @@ -370,6 +375,7 @@ def POSTSOLVE(line): "length_threshold": length_threshold, "lines_threshold": lines_threshold, "_11": _mypostloader, + "stringreplace": stringreplace, } useranklist = globalconfig["postprocess_rank"] usedpostprocessconfig = postprocessconfig diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index f3364d15..12f039d7 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -493,17 +493,34 @@ class autosql(sqlite3.Connection): @tryprint -def parsemayberegexreplace(dic: dict, res: str): - for item in dic: - if item["regex"]: - res = re.sub( - codecs.escape_decode(bytes(item["key"], "utf-8"))[0].decode("utf-8"), - codecs.escape_decode(bytes(item["value"], "utf-8"))[0].decode("utf-8"), - res, - ) +def parsemayberegexreplace(lst: list, line: str): + for fil in lst: + regex = fil.get("regex", False) + escape = fil.get("escape", regex) + key = fil.get("key", "") + value = fil.get("value", "") + if key == "": + continue + if regex: + if escape: + line = re.sub( + codecs.escape_decode(bytes(key, "utf-8"))[0].decode("utf-8"), + codecs.escape_decode(bytes(value, "utf-8"))[0].decode("utf-8"), + ) + + else: + + line = re.sub(key, value) else: - res = res.replace(item["key"], item["value"]) - return res + if escape: + line = line.replace( + codecs.escape_decode(bytes(key, "utf-8"))[0].decode("utf-8"), + codecs.escape_decode(bytes(value, "utf-8"))[0].decode("utf-8"), + ) + else: + line = line.replace(key, value) + + return line def checkpostlangmatch(name): diff --git a/LunaTranslator/LunaTranslator/transoptimi/noundict.py b/LunaTranslator/LunaTranslator/transoptimi/noundict.py index 0b2d0aff..66ba8efb 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/noundict.py +++ b/LunaTranslator/LunaTranslator/transoptimi/noundict.py @@ -16,33 +16,6 @@ class noundictconfigdialog(LDialog): self.button.setFocus() self.apply() - def showmenu(self, table: TableViewW, pos): - r = table.currentIndex().row() - if r < 0: - return - menu = QMenu(table) - up = LAction("上移") - down = LAction("下移") - copy = LAction("复制") - paste = LAction("粘贴") - menu.addAction(up) - menu.addAction(down) - menu.addAction(copy) - menu.addAction(paste) - action = menu.exec(table.cursor().pos()) - - if action == up: - - table.moverank(-1) - - elif action == down: - table.moverank(1) - elif action == copy: - table.copytable() - - elif action == paste: - table.pastetable() - def apply(self): rows = self.model.rowCount() self.configdict.clear() @@ -84,10 +57,7 @@ class noundictconfigdialog(LDialog): table = TableViewW(self) table.setModel(model) table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) - table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) - table.customContextMenuRequested.connect( - functools.partial(self.showmenu, table) - ) + table.setsimplemenu() button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"]) self.table = table @@ -154,34 +124,6 @@ class noundictconfigdialog_private(LDialog): self.button.setFocus() self.apply() - def showmenu(self, table: TableViewW, pos): - r = table.currentIndex().row() - if r < 0: - return - menu = QMenu(table) - up = LAction("上移") - down = LAction("下移") - copy = LAction("复制") - paste = LAction("粘贴") - menu.addAction(up) - menu.addAction(down) - menu.addAction(copy) - menu.addAction(paste) - action = menu.exec(table.cursor().pos()) - - if action == up: - - table.moverank(-1) - - elif action == down: - table.moverank(1) - - elif action == copy: - table.copytable() - - elif action == paste: - table.pastetable() - def apply(self): self.table.dedumpmodel(0) rows = self.model.rowCount() @@ -214,10 +156,7 @@ class noundictconfigdialog_private(LDialog): table = TableViewW(self) table.setModel(model) table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) - table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) - table.customContextMenuRequested.connect( - functools.partial(self.showmenu, table) - ) + table.setsimplemenu() button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"]) self.table = table button.btn1clicked.connect(table.insertplainrow) diff --git a/LunaTranslator/LunaTranslator/transoptimi/transerrorfix.py b/LunaTranslator/LunaTranslator/transoptimi/transerrorfix.py index 9662d99c..9b733864 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/transerrorfix.py +++ b/LunaTranslator/LunaTranslator/transoptimi/transerrorfix.py @@ -13,7 +13,7 @@ class Process: parent_window, transerrorfixdictconfig["dict_v2"], "翻译结果修正_设置", - ["正则", "翻译", "替换"], + ["正则",'转义', "翻译", "替换"], ) @staticmethod @@ -23,7 +23,7 @@ class Process: parent_window, savehook_new_data[gameuid]["transerrorfix"], "翻译结果修正_设置", - ["正则", "翻译", "替换"], + ["正则",'转义', "翻译", "替换"], ).setWindowIcon(getExeIcon(uid2gamepath[gameuid], cache=True)) def process_after(self, res, mp1): diff --git a/LunaTranslator/LunaTranslator/transoptimi/vndbnamemap.py b/LunaTranslator/LunaTranslator/transoptimi/vndbnamemap.py index 85c96975..e5f4ccca 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/vndbnamemap.py +++ b/LunaTranslator/LunaTranslator/transoptimi/vndbnamemap.py @@ -1,6 +1,6 @@ from myutils.config import globalconfig, savehook_new_data, uid2gamepath -from myutils.utils import postusewhich -from gui.inputdialog import postconfigdialog_ +from myutils.utils import postusewhich, parsemayberegexreplace +from gui.inputdialog import noundictconfigdialog1 import gobject, json, functools from myutils.hwnd import getExeIcon @@ -10,29 +10,22 @@ class Process: @staticmethod def get_setting_window(parent_window): return ( - postconfigdialog_( + noundictconfigdialog1( parent_window, - globalconfig["global_namemap"], + globalconfig["global_namemap2"], "专有名词翻译_直接替换_设置", - ["原文", "翻译"], + ["正则",'转义', "原文", "翻译"], ), ) @staticmethod def get_setting_window_gameprivate(parent_window, gameuid): - def checkchange(gameuid, __): - __2 = json.dumps(savehook_new_data[gameuid]["namemap"]) - if __ != __2: - savehook_new_data[gameuid]["vndbnamemap_modified"] = True - - __ = json.dumps(savehook_new_data[gameuid]["namemap"]) - postconfigdialog_( + noundictconfigdialog1( parent_window, - savehook_new_data[gameuid]["namemap"], + savehook_new_data[gameuid]["namemap2"], "专有名词翻译_直接替换_设置", - ["原文", "翻译"], - closecallback=functools.partial(checkchange, gameuid, __), + ["正则",'转义', "原文", "翻译"], ).setWindowIcon(getExeIcon(uid2gamepath[gameuid], cache=True)) @property @@ -42,20 +35,17 @@ class Process: def usewhich(self) -> dict: which = postusewhich("vndbnamemap") if which == 1: - return globalconfig["global_namemap"] + return globalconfig["global_namemap2"] elif which == 2: gameuid = gobject.baseobject.textsource.gameuid - return savehook_new_data[gameuid]["namemap"] + return savehook_new_data[gameuid]["namemap2"] elif which == 3: - _ = {} - _.update(globalconfig["global_namemap"]) - gameuid = gobject.baseobject.textsource.gameuid - _.update(savehook_new_data[gameuid]["namemap"]) - return _ + return savehook_new_data[gameuid]["namemap2"] + globalconfig["global_namemap2"] def process_before(self, s): namemap = self.usewhich() + s=parsemayberegexreplace(namemap,s) bettermap = {} for k, v in namemap.items(): for sp in ["・", " "]: diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index aa2e53f4..3faaa63b 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -499,7 +499,7 @@ 1200, 600 ], - "global_namemap": {}, + "global_namemap2": [], "settingfontsize": 12, "filter_chaos_code": false, "accept_encoding": [ diff --git a/LunaTranslator/files/defaultconfig/postprocessconfig.json b/LunaTranslator/files/defaultconfig/postprocessconfig.json index 7055fd96..dddff35f 100644 --- a/LunaTranslator/files/defaultconfig/postprocessconfig.json +++ b/LunaTranslator/files/defaultconfig/postprocessconfig.json @@ -1,4 +1,11 @@ { + "stringreplace": { + "use": false, + "name": "字符串替换", + "args": { + "internal":[] + } + }, "_remove_non_shiftjis_char": { "use": false, "name": "过滤文本中的非日语字符集字符" @@ -157,21 +164,21 @@ }, "_7": { "use": true, - "name": "简单字符串替换", + "name": "!_不推荐使用_简单字符串替换_!", "args": { "替换内容": {} } }, "_7_zhuanyi": { "use": true, - "name": "转义字符串替换", + "name": "!_不推荐使用_转义字符串替换_!", "args": { "替换内容": {} } }, "_8": { "use": false, - "name": "正则表达式替换", + "name": "!_不推荐使用_正则表达式替换_!", "args": { "替换内容": {} } diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index 714b9545..a830f692 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -849,5 +849,8 @@ "语音指定": "صوت محدد", "指定为": "تعيين", "跳过": "تخطي", - "作用于翻译": "العمل على الترجمة" + "作用于翻译": "العمل على الترجمة", + "字符串替换": "سلسلة استبدال", + "转义": "هروب", + "不推荐使用": "لا ينصح باستخدام" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index 8f37d3fa..ba45e54d 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -849,5 +849,8 @@ "语音指定": "語音指定", "指定为": "指定為", "跳过": "跳過", - "作用于翻译": "作用於翻譯" + "作用于翻译": "作用於翻譯", + "字符串替换": "字串替換", + "转义": "轉義", + "不推荐使用": "不推薦使用" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cs.json b/LunaTranslator/files/lang/cs.json index 48eccf7f..af05379f 100644 --- a/LunaTranslator/files/lang/cs.json +++ b/LunaTranslator/files/lang/cs.json @@ -849,5 +849,8 @@ "语音指定": "Označení hlasu", "指定为": "Určeno jako", "跳过": "přeskočit", - "作用于翻译": "Použití na překlad" + "作用于翻译": "Použití na překlad", + "字符串替换": "Náhrada řetězce", + "转义": "Útěk", + "不推荐使用": "Nedoporučuje se k použití" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/de.json b/LunaTranslator/files/lang/de.json index ebcc37f4..499bb402 100644 --- a/LunaTranslator/files/lang/de.json +++ b/LunaTranslator/files/lang/de.json @@ -849,5 +849,8 @@ "语音指定": "Sprachbezeichnung", "指定为": "Bestimmt als", "跳过": "überspringen", - "作用于翻译": "Auf Übersetzungen angewendet" + "作用于翻译": "Auf Übersetzungen angewendet", + "字符串替换": "Zeichenfolgenersatz", + "转义": "Flucht", + "不推荐使用": "Nicht empfohlen für die Anwendung" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index 6724d802..33a6c877 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -849,5 +849,8 @@ "语音指定": "Voice designation", "指定为": "Designated as", "跳过": "skip", - "作用于翻译": "Applied to translation" + "作用于翻译": "Applied to translation", + "字符串替换": "String replacement", + "转义": "Escaping", + "不推荐使用": "Not recommended for use" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index e00c2ac8..b3a793e1 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -849,5 +849,8 @@ "语音指定": "Designación de voz", "指定为": "Designado como", "跳过": "Saltar", - "作用于翻译": "Actuar sobre la traducción" + "作用于翻译": "Actuar sobre la traducción", + "字符串替换": "Reemplazo de cadenas", + "转义": "Transliteración", + "不推荐使用": "No se recomienda usar" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index 02969981..504110d9 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -849,5 +849,8 @@ "语音指定": "Désignation vocale", "指定为": "Désigné comme", "跳过": "Sauter", - "作用于翻译": "Agir sur la traduction" + "作用于翻译": "Agir sur la traduction", + "字符串替换": "Remplacement de chaîne", + "转义": "échappement", + "不推荐使用": "Utilisation non recommandée" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 6ac6fe24..f61f7859 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -849,5 +849,8 @@ "语音指定": "Denominazione vocale", "指定为": "Designato come", "跳过": "salta", - "作用于翻译": "Applicato alla traduzione" + "作用于翻译": "Applicato alla traduzione", + "字符串替换": "Sostituzione stringa", + "转义": "Scappare", + "不推荐使用": "Non raccomandato per l'uso" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index c1d30e53..bb5ebf41 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -849,5 +849,8 @@ "语音指定": "音声指定", "指定为": "指定#シテイ#", "跳过": "スキップ", - "作用于翻译": "翻訳に役立つ" + "作用于翻译": "翻訳に役立つ", + "字符串替换": "文字列置換", + "转义": "エスケープ", + "不推荐使用": "使用を推奨しない" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index 33fec103..c5eadb74 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -849,5 +849,8 @@ "语音指定": "음성 지정", "指定为": "다음으로 지정", "跳过": "건너뛰기", - "作用于翻译": "번역에 적용" + "作用于翻译": "번역에 적용", + "字符串替换": "문자열 대체", + "转义": "전의", + "不推荐使用": "권장하지 않음" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/nl.json b/LunaTranslator/files/lang/nl.json index f4270393..87cdbfc5 100644 --- a/LunaTranslator/files/lang/nl.json +++ b/LunaTranslator/files/lang/nl.json @@ -849,5 +849,8 @@ "语音指定": "Stembepaling", "指定为": "Aangeduid als", "跳过": "overslaan", - "作用于翻译": "Toegepast op vertaling" + "作用于翻译": "Toegepast op vertaling", + "字符串替换": "Vervanging van tekenreeks", + "转义": "Ontsnappen", + "不推荐使用": "Niet aanbevolen voor gebruik" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index a6762f31..0c4fa601 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -849,5 +849,8 @@ "语音指定": "Oznaczenie głosu", "指定为": "Wyznaczony jako", "跳过": "pominięcie", - "作用于翻译": "Zastosowanie do tłumaczenia" + "作用于翻译": "Zastosowanie do tłumaczenia", + "字符串替换": "Zastąpienie ciągu", + "转义": "Ucieczka", + "不推荐使用": "Nie zaleca się stosowania" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pt.json b/LunaTranslator/files/lang/pt.json index 52076286..c2d6a495 100644 --- a/LunaTranslator/files/lang/pt.json +++ b/LunaTranslator/files/lang/pt.json @@ -849,5 +849,8 @@ "语音指定": "Designação da voz", "指定为": "Designado como", "跳过": "pular", - "作用于翻译": "Aplicado à tradução" + "作用于翻译": "Aplicado à tradução", + "字符串替换": "Substituição de strings", + "转义": "Escapar", + "不推荐使用": "Não recomendado para utilização" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index e6350e2e..525d6553 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -849,5 +849,8 @@ "语音指定": "Голосовое назначение", "指定为": "Назначено", "跳过": "Пропустить", - "作用于翻译": "Роль перевода" + "作用于翻译": "Роль перевода", + "字符串替换": "Замена строки", + "转义": "Транслитерация", + "不推荐使用": "Не рекомендуется использовать" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/sv.json b/LunaTranslator/files/lang/sv.json index 218cf73e..3accd328 100644 --- a/LunaTranslator/files/lang/sv.json +++ b/LunaTranslator/files/lang/sv.json @@ -849,5 +849,8 @@ "语音指定": "Röstbeteckning", "指定为": "Utnämnd som", "跳过": "hoppa över", - "作用于翻译": "Tillämpad på översättning" + "作用于翻译": "Tillämpad på översättning", + "字符串替换": "Strängersättning", + "转义": "Flykt", + "不推荐使用": "Rekommenderas inte för användning" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index 3e16d198..c89b9ef9 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -849,5 +849,8 @@ "语音指定": "การกำหนดเสียง", "指定为": "กำหนดให้เป็น", "跳过": "ข้าม", - "作用于翻译": "บทบาทในการแปล" + "作用于翻译": "บทบาทในการแปล", + "字符串替换": "การแทนที่สตริง", + "转义": "แปลความหมาย", + "不推荐使用": "ไม่แนะนำให้ใช้" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index 9ee7d711..8af08629 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -849,5 +849,8 @@ "语音指定": "Ses tasarımı", "指定为": "Şöyle tasarlanmıştır", "跳过": "atla", - "作用于翻译": "Çevirmeye uygulandı" + "作用于翻译": "Çevirmeye uygulandı", + "字符串替换": "String Replacement", + "转义": "Kaçmak", + "不推荐使用": "Kullanmak için önerilmez" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 4771694e..bfb13109 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -849,5 +849,8 @@ "语音指定": "Визначення голосу", "指定为": "Визначено як", "跳过": "пропустити", - "作用于翻译": "Застосовано до перекладу" + "作用于翻译": "Застосовано до перекладу", + "字符串替换": "Заміна рядків", + "转义": "Бег", + "不推荐使用": "Не рекомендується використовувати" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index fcaaaaa5..bec41fa1 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -849,5 +849,8 @@ "语音指定": "Chỉ định giọng nói", "指定为": "Xác định là", "跳过": "Bỏ qua", - "作用于翻译": "Hành động để dịch" + "作用于翻译": "Hành động để dịch", + "字符串替换": "Thay thế chuỗi", + "转义": "Thoát", + "不推荐使用": "Không khuyến khích sử dụng" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index dddbaa0b..854d992c 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -849,5 +849,8 @@ "语音指定": "", "指定为": "", "跳过": "", - "作用于翻译": "" + "作用于翻译": "", + "字符串替换": "", + "转义": "", + "不推荐使用": "" } \ No newline at end of file diff --git a/docs/zh/textprocess.md b/docs/zh/textprocess.md index 63d3957b..56072170 100644 --- a/docs/zh/textprocess.md +++ b/docs/zh/textprocess.md @@ -85,19 +85,19 @@ 略 -**18. 简单字符串替换** +~~**18. 简单字符串替换**~~ 过时的,不再推荐使用,请改用**字符串替换** -不止是替换,主要也可以用来过滤。可以将固定的若干乱码字符、反复刷新的倒三角字符等通过替换成空白来进行过滤。 +~~不止是替换,主要也可以用来过滤。可以将固定的若干乱码字符、反复刷新的倒三角字符等通过替换成空白来进行过滤。~~ -**19. 转义字符串替换** +~~**19. 转义字符串替换**~~ 过时的,不再推荐使用,请改用**字符串替换** -主要是可以支持`\n`来表示换行符,从而实现可以过滤仅在换行符前后出现的字符。 +~~主要是可以支持`\n`来表示换行符,从而实现可以过滤仅在换行符前后出现的字符。~~ -**20. 正则表达式替换** +~~**20. 正则表达式替换**~~ 过时的,不再推荐使用,请改用**字符串替换** -注:**这个输入的内容都是转义字符串**,也就是说比如你在外面写python代码`re.sub(r"\n","")`来测试再填入,想把`\n`这两个字符替换掉,实际上这里会替换掉**换行符**,你想在外面测试的话请用`re.sub("\\n","")`这样来测试 +~~注:**这个输入的内容都是转义字符串**,也就是说比如你在外面写python代码`re.sub(r"\n","")`来测试再填入,想把`\n`这两个字符替换掉,实际上这里会替换掉**换行符**,你想在外面测试的话请用`re.sub("\\n","")`这样来测试~~ **21. 去除重复行_ABCDBCDCDD->ABCD** @@ -122,4 +122,12 @@ def POSTSOLVE(line): # 请在这里编写自定义处理 return line -``` \ No newline at end of file +``` + +**25. 字符串替换** + +原`简单字符串替换` `转义字符串替换` `正则表达式替换`的整合,同时可设置`正则`和`转义`两个选项。 +原正则表达式替换存在一定缺陷,输入的表达式是默认转义的,因此输入起来非常麻烦。 +该处理添加时将默认使用简单替换,激活正则后将使用字符串字面量进行正则处理。仅激活转义后才使用转义字符串进行处理。 + +旧的处理词典在更新后首次运行将自动迁移到新的处理词典中。在之后的很长一段时间中,旧的处理不会被删除,但不会再进行维护。 \ No newline at end of file diff --git a/docs/zh/transoptimi.md b/docs/zh/transoptimi.md index f600037e..87215db4 100644 --- a/docs/zh/transoptimi.md +++ b/docs/zh/transoptimi.md @@ -2,7 +2,7 @@ #### **1. 专有名词翻译 直接替换** -这种方法会在翻译之前,直接用译文将原文进行替换。 +这种方法会在翻译之前,直接用译文将原文进行替换。支持使用`正则` `转义`进行更复杂的替换。 当游戏从VNDB加载元数据时,会查询游戏中的人名信息作为预设的词典。不过译文由于VNDB的原因是英文,可以自行进行修改译文成中文。 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index fb2bff1f..8c5b8e03 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -28,8 +28,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version) include(generate_product_version) set(VERSION_MAJOR 5) -set(VERSION_MINOR 22) -set(VERSION_PATCH 2) +set(VERSION_MINOR 23) +set(VERSION_PATCH 0) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)