初步的 kvmd 国际化(汉化)支持

1. 添加汉化文件
2. 添加 Lanuages().gettext 函数处理字符替换
3. 修改相关字符串调用
This commit is contained in:
mofeng-git
2024-08-06 21:45:16 +08:00
parent 6a966af5fb
commit 20927c7226
34 changed files with 999 additions and 113 deletions

View File

@@ -41,6 +41,8 @@ from ....validators.basic import valid_float_f01
from ....validators.os import valid_abs_path
from ....validators.hw import valid_tty_speed
from ....lanuages import Lanuages
from .. import BaseHid
from .chip import ChipResponseError
@@ -82,6 +84,8 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
self.__keyboard = Keyboard()
self.__mouse = Mouse()
self.gettext=Lanuages().gettext
@classmethod
def get_plugin_options(cls) -> dict:
return {
@@ -92,7 +96,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
}
def sysprep(self) -> None:
get_logger(0).info("Starting HID daemon ...")
get_logger(0).info(self.gettext("Starting HID daemon ..."))
self.start()
async def get_state(self) -> dict:
@@ -134,7 +138,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
@aiotools.atomic_fg
async def cleanup(self) -> None:
if self.is_alive():
get_logger(0).info("Stopping HID daemon ...")
get_logger(0).info(self.gettext("Stopping HID daemon ..."))
self.__stop_event.set()
if self.is_alive() or self.exitcode is not None:
self.join()
@@ -171,7 +175,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
_ = keyboard_output
if mouse_output is not None:
get_logger(0).info("HID : mouse output = %s", mouse_output)
get_logger(0).info(self.gettext("HID : mouse output = %s"), mouse_output)
absolute = (mouse_output == "usb")
self.__mouse.set_absolute(absolute)
self._set_jiggler_absolute(absolute)
@@ -201,7 +205,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
try:
self.__hid_loop()
except Exception:
logger.exception("Unexpected error in the run loop")
logger.exception(self.gettext("Unexpected error in the run loop"))
time.sleep(1)
def __hid_loop(self) -> None:
@@ -224,7 +228,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
self.__process_cmd(conn, cmd)
except Exception:
self.clear_events()
get_logger(0).exception("Unexpected error in the HID loop")
get_logger(0).exception(self.gettext("Unexpected error in the HID loop"))
time.sleep(2)
def __process_cmd(self, conn: ChipConnection, cmd: bytes) -> bool: # pylint: disable=too-many-branches

View File

@@ -25,6 +25,8 @@ import contextlib
from typing import Generator
from ....lanuages import Lanuages
# =====
class ChipResponseError(Exception):
@@ -35,6 +37,7 @@ class ChipResponseError(Exception):
class ChipConnection:
def __init__(self, tty: serial.Serial) -> None:
self.__tty = tty
self.gettext=Lanuages().gettext
def xfer(self, cmd: bytes) -> int:
self.__send(cmd)
@@ -52,16 +55,16 @@ class ChipConnection:
def __recv(self) -> int:
data = self.__tty.read(5)
if len(data) < 5:
raise ChipResponseError("Too short response, HID might be disconnected")
raise ChipResponseError(self.gettext("Too short response, HID might be disconnected"))
if data and data[4]:
data += self.__tty.read(data[4] + 1)
if self.__make_checksum(data[:-1]) != data[-1]:
raise ChipResponseError("Invalid response checksum")
raise ChipResponseError(self.gettext("Invalid response checksum"))
if data[4] == 1 and data[5] != 0:
raise ChipResponseError(f"Response error code = {data[5]!r}")
raise ChipResponseError(self.gettext(f"Response error code = {data[5]!r}"))
# led_byte (info) response
return (data[7] if data[3] == 0x81 else -1)