update
This commit is contained in:
parent
e1419d5ab8
commit
4b99d6d87d
@ -20,10 +20,63 @@ from Difficult_Rocket import DR_runtime, DR_option
|
|||||||
from Difficult_Rocket.utils import tools
|
from Difficult_Rocket.utils import tools
|
||||||
from Difficult_Rocket.exception.language import *
|
from Difficult_Rocket.exception.language import *
|
||||||
|
|
||||||
"""
|
|
||||||
这部分代码使用了中文编程,why?
|
class Translated:
|
||||||
你觉得呢?
|
def __init__(self, value: Union[list, tuple, dict, str], raise_error: bool = False):
|
||||||
"""
|
self.value = value
|
||||||
|
self.raise_error = raise_error
|
||||||
|
self.item_names = []
|
||||||
|
|
||||||
|
def __getattr__(self, item):
|
||||||
|
if hasattr(object, item):
|
||||||
|
return getattr(object, item)
|
||||||
|
self.item_names.append(item)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __getitem__(self, item):
|
||||||
|
self.item_names.append(item)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
if not self.item_names:
|
||||||
|
return self.value
|
||||||
|
else:
|
||||||
|
return f'{self.value}.{".".join(self.item_names)}'
|
||||||
|
|
||||||
|
|
||||||
|
class Translating:
|
||||||
|
def __init__(self, value: Union[Dict[str, Any], list, tuple], raise_error: bool = False, get_list: list = None):
|
||||||
|
self.value: Union[Dict[str, Any], list, tuple] = value
|
||||||
|
self.raise_error = raise_error
|
||||||
|
self.get_list = get_list or []
|
||||||
|
|
||||||
|
def __getitem__(self, item: Union[str, Hashable]) -> Union["Translating", Translated]:
|
||||||
|
cache_get_list = self.get_list.copy()
|
||||||
|
cache_get_list.append(item)
|
||||||
|
try:
|
||||||
|
cache = self.value[item]
|
||||||
|
except (KeyError, TypeError):
|
||||||
|
if DR_option.report_translate_no_found:
|
||||||
|
frame = inspect.currentframe()
|
||||||
|
last_frame = frame.f_back
|
||||||
|
if last_frame.f_code == self.__getattr__.__code__:
|
||||||
|
last_frame = last_frame.f_back
|
||||||
|
call_info = f'Translate Not Found at {last_frame.f_code.co_name} by {".".join(cache_get_list)} at:' \
|
||||||
|
f'{last_frame.f_code.co_filename}:{last_frame.f_lineno}'
|
||||||
|
print(call_info)
|
||||||
|
if not self.raise_error:
|
||||||
|
return Translated('.'.join(cache_get_list), raise_error=False)
|
||||||
|
else:
|
||||||
|
raise TranslateKeyNotFound(item_names=cache_get_list)
|
||||||
|
return Translating(value=cache, raise_error=self.raise_error, get_list=cache_get_list)
|
||||||
|
|
||||||
|
def __getattr__(self, item: Union[str, Hashable]) -> Union["Translating", Translated]:
|
||||||
|
if hasattr(object, item):
|
||||||
|
return getattr(object, item)
|
||||||
|
return self.__getitem__(item)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.value)
|
||||||
|
|
||||||
class Translated:
|
class Translated:
|
||||||
def __init__(self, value: Union[list, tuple, dict, str], raise_error: bool = False):
|
def __init__(self, value: Union[list, tuple, dict, str], raise_error: bool = False):
|
||||||
|
23
README.md
23
README.md
@ -39,26 +39,26 @@
|
|||||||
- `开发平台 1 - Windows 10`
|
- `开发平台 1 - Windows 10`
|
||||||
- `Python 3.8.10`
|
- `Python 3.8.10`
|
||||||
- `Windows10 x64`
|
- `Windows10 x64`
|
||||||
- `json5 0.9.9`
|
|
||||||
- `pillow 9.2.0`
|
- `pillow 9.2.0`
|
||||||
- `pyperclip 1.8.2`
|
- `pyperclip 1.8.2`
|
||||||
- `pyglet 2.0b2`
|
- `pyglet 2.0`
|
||||||
- `xmltodict 0.12.0`
|
- `xmltodict 0.12.0`
|
||||||
- `tomlkit 0.11.5`
|
- `tomlkit 0.11.5`
|
||||||
- `AMD R5 5600X`
|
- `AMD R5 5600X`
|
||||||
- `AMD RX 550 4G`
|
- `AMD RX 550 4G`
|
||||||
- `开发平台 2 - macOS Big Sur`
|
|
||||||
- `Python 3.8.10`
|
[//]: # (- `开发平台 2 - macOS Big Sur`)
|
||||||
- `macOS Big Sur 11.2.1`
|
[//]: # ( - `Python 3.8.10`)
|
||||||
- `Pyglet 1.5.15`
|
[//]: # ( - `macOS Big Sur 11.2.1`)
|
||||||
- `Json5 0.9.5`
|
[//]: # ( - `Pyglet 1.5.15`)
|
||||||
- `pillow 8.1.2`
|
[//]: # ( - `Json5 0.9.5`)
|
||||||
- `Intel I5 8279U`
|
[//]: # ( - `pillow 8.1.2`)
|
||||||
|
[//]: # ( - `Intel I5 8279U`)
|
||||||
|
|
||||||
## 需要的Python模块
|
## 需要的Python模块
|
||||||
|
|
||||||
- `json5` (已经内置 V0.9.6 路径:`./libs/json5`)
|
|
||||||
- `tomlkit`
|
- `tomlkit`
|
||||||
|
- `rtoml`
|
||||||
- `pyglet` (已经内置 V2.0b2 路径:`./libs/pyglet`)
|
- `pyglet` (已经内置 V2.0b2 路径:`./libs/pyglet`)
|
||||||
- `xmltodict` (已经内置 V0.12.0 路径:`./libs/xmltodict`)
|
- `xmltodict` (已经内置 V0.12.0 路径:`./libs/xmltodict`)
|
||||||
- `pyperclip` (已经内置 V1.8.2 路径: `./libs/pyperclip`)
|
- `pyperclip` (已经内置 V1.8.2 路径: `./libs/pyperclip`)
|
||||||
@ -68,8 +68,7 @@
|
|||||||
## 感谢
|
## 感谢
|
||||||
|
|
||||||
- [pyglet](https://github.com/pyglet/pyglet) : GUI 和画面渲染
|
- [pyglet](https://github.com/pyglet/pyglet) : GUI 和画面渲染
|
||||||
- `json5`: json5 解析器
|
- `tomlkit` / `rtoml` : toml 解析器
|
||||||
- `tomlkit`: toml 解析器
|
|
||||||
- `xmltodict`: xml 与 dict 转换器
|
- `xmltodict`: xml 与 dict 转换器
|
||||||
- `pyperclip`: 剪贴板!
|
- `pyperclip`: 剪贴板!
|
||||||
- [@Rayawa](https://github.com/Rayawa) : 文档矫正 & 翻译部分 lang
|
- [@Rayawa](https://github.com/Rayawa) : 文档矫正 & 翻译部分 lang
|
||||||
|
@ -8,5 +8,4 @@ pymunk
|
|||||||
rtoml
|
rtoml
|
||||||
setuptools
|
setuptools
|
||||||
Cython
|
Cython
|
||||||
colorama
|
|
||||||
viztracer
|
viztracer
|
Loading…
Reference in New Issue
Block a user