mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 09:01:54 +08:00
初步的 kvmd 国际化(汉化)支持
1. 添加汉化文件 2. 添加 Lanuages().gettext 函数处理字符替换 3. 修改相关字符串调用
This commit is contained in:
@@ -40,6 +40,7 @@ from ... import aiotools
|
||||
from .. import BasePlugin
|
||||
from .. import get_plugin_class
|
||||
|
||||
from ...lanuages import Lanuages
|
||||
|
||||
# =====
|
||||
class MsdError(Exception):
|
||||
@@ -52,37 +53,44 @@ class MsdOperationError(OperationError, MsdError):
|
||||
|
||||
class MsdIsBusyError(IsBusyError, MsdError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("Performing another MSD operation, please try again later")
|
||||
gettext=Lanuages().gettext
|
||||
super().__init__(gettext("Performing another MSD operation, please try again later"))
|
||||
|
||||
|
||||
class MsdOfflineError(MsdOperationError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("MSD is not found")
|
||||
gettext=Lanuages().gettext
|
||||
super().__init__(gettext("MSD is not found"))
|
||||
|
||||
|
||||
class MsdConnectedError(MsdOperationError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("MSD is connected to Server, but shouldn't for this operation")
|
||||
gettext=Lanuages().gettext
|
||||
super().__init__(gettext("MSD is connected to Server, but shouldn't for this operation"))
|
||||
|
||||
|
||||
class MsdDisconnectedError(MsdOperationError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("MSD is disconnected from Server, but should be for this operation")
|
||||
gettext=Lanuages().gettext
|
||||
super().__init__(gettext("MSD is disconnected from Server, but should be for this operation"))
|
||||
|
||||
|
||||
class MsdImageNotSelected(MsdOperationError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("The image is not selected")
|
||||
gettext=Lanuages().gettext
|
||||
super().__init__(gettext("The image is not selected"))
|
||||
|
||||
|
||||
class MsdUnknownImageError(MsdOperationError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("The image is not found in the storage")
|
||||
gettext=Lanuages().gettext
|
||||
super().__init__(gettext("The image is not found in the storage"))
|
||||
|
||||
|
||||
class MsdImageExistsError(MsdOperationError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("This image is already exists")
|
||||
gettext=Lanuages().gettext
|
||||
super().__init__(gettext("This image is already exists"))
|
||||
|
||||
|
||||
# =====
|
||||
|
||||
@@ -31,11 +31,13 @@ from . import BaseMsdReader
|
||||
from . import BaseMsdWriter
|
||||
from . import BaseMsd
|
||||
|
||||
from ...lanuages import Lanuages
|
||||
|
||||
# =====
|
||||
class MsdDisabledError(MsdOperationError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("MSD is disabled")
|
||||
gettext=Lanuages().gettext
|
||||
super().__init__(gettext("MSD is disabled"))
|
||||
|
||||
|
||||
# =====
|
||||
|
||||
@@ -28,6 +28,7 @@ import time
|
||||
|
||||
from typing import AsyncGenerator
|
||||
|
||||
from ....lanuages import Lanuages
|
||||
from ....logging import get_logger
|
||||
|
||||
from ....inotify import InotifyMask
|
||||
@@ -43,6 +44,8 @@ from ....validators.kvm import valid_msd_image_name
|
||||
from .... import aiotools
|
||||
from .... import fstab
|
||||
|
||||
from ....lanuages import Lanuages
|
||||
|
||||
from .. import MsdIsBusyError
|
||||
from .. import MsdOfflineError
|
||||
from .. import MsdConnectedError
|
||||
@@ -58,7 +61,6 @@ from .storage import Image
|
||||
from .storage import Storage
|
||||
from .drive import Drive
|
||||
|
||||
|
||||
# =====
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class _DriveState:
|
||||
@@ -140,9 +142,10 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
||||
|
||||
self.__notifier = aiotools.AioNotifier()
|
||||
self.__state = _State(self.__notifier)
|
||||
self.gettext=Lanuages().gettext
|
||||
|
||||
logger = get_logger(0)
|
||||
logger.info("Using OTG gadget %r as MSD", gadget)
|
||||
logger.info(self.gettext("Using OTG gadget %r as MSD"), gadget)
|
||||
aiotools.run_sync(self.__reload_state(notify=False))
|
||||
|
||||
@classmethod
|
||||
@@ -217,7 +220,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
||||
self.__drive.set_rw_flag(False)
|
||||
await self.__storage.remount_rw(False)
|
||||
except Exception:
|
||||
get_logger(0).exception("Can't reset MSD properly")
|
||||
get_logger(0).exception(self.gettext("Can't reset MSD properly"))
|
||||
|
||||
@aiotools.atomic_fg
|
||||
async def cleanup(self) -> None:
|
||||
@@ -436,7 +439,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
||||
if need_reload_state:
|
||||
await self.__reload_state()
|
||||
except Exception:
|
||||
logger.exception("Unexpected MSD watcher error")
|
||||
logger.exception(self.gettext("Unexpected MSD watcher error"))
|
||||
time.sleep(1)
|
||||
|
||||
async def __reload_state(self, notify: bool=True) -> None:
|
||||
@@ -455,13 +458,13 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
||||
if self.__state.vd is None and drive_state.image is None:
|
||||
# Если только что включились и образ не подключен - попробовать
|
||||
# перемонтировать хранилище (и создать images и meta).
|
||||
logger.info("Probing to remount storage ...")
|
||||
logger.info(self.gettext("Probing to remount storage ..."))
|
||||
await self.__storage.remount_rw(True)
|
||||
await self.__storage.remount_rw(False)
|
||||
await self.__setup_initial()
|
||||
|
||||
except Exception:
|
||||
logger.exception("Error while reloading MSD state; switching to offline")
|
||||
logger.exception(self.gettext("Error while reloading MSD state; switching to offline"))
|
||||
self.__state.storage = None
|
||||
self.__state.vd = None
|
||||
|
||||
@@ -489,12 +492,12 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
||||
logger = get_logger(0)
|
||||
image = await self.__storage.make_image_by_name(self.__initial_image)
|
||||
if (await image.exists()):
|
||||
logger.info("Setting up initial image %r ...", self.__initial_image)
|
||||
logger.info(self.gettext("Setting up initial image %r ..."), self.__initial_image)
|
||||
try:
|
||||
self.__drive.set_rw_flag(False)
|
||||
self.__drive.set_cdrom_flag(self.__initial_cdrom)
|
||||
self.__drive.set_image_path(image.path)
|
||||
except Exception:
|
||||
logger.exception("Can't setup initial image: ignored")
|
||||
logger.exception(self.gettext("Can't setup initial image: ignored"))
|
||||
else:
|
||||
logger.error("Can't find initial image %r: ignored", self.__initial_image)
|
||||
logger.error(self.gettext("Can't find initial image %r: ignored"), self.__initial_image)
|
||||
|
||||
@@ -27,11 +27,13 @@ from .... import usb
|
||||
|
||||
from .. import MsdOperationError
|
||||
|
||||
from ....lanuages import Lanuages
|
||||
|
||||
|
||||
# =====
|
||||
class MsdDriveLockedError(MsdOperationError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("MSD drive is locked on IO operation")
|
||||
super().__init__(Lanuages().gettext("MSD drive is locked on IO operation"))
|
||||
|
||||
|
||||
# =====
|
||||
|
||||
@@ -31,6 +31,8 @@ from typing import Optional
|
||||
import aiofiles
|
||||
import aiofiles.os
|
||||
|
||||
from ....lanuages import Lanuages
|
||||
|
||||
from .... import aiotools
|
||||
from .... import aiohelpers
|
||||
|
||||
@@ -292,4 +294,4 @@ class Storage(_StorageDc):
|
||||
async def remount_rw(self, rw: bool, fatal: bool=True) -> None:
|
||||
if not (await aiohelpers.remount("MSD", self.__remount_cmd, rw)):
|
||||
if fatal:
|
||||
raise MsdError("Can't execute remount helper")
|
||||
raise MsdError(Lanuages().gettext("Can't execute remount helper"))
|
||||
|
||||
Reference in New Issue
Block a user