Pārlūkot izejas kodu

feat(module): Support translation on the server side

ryland 1 gadu atpakaļ
vecāks
revīzija
8edbdad00b

+ 3 - 0
assets/i18n/en-US.json

@@ -0,0 +1,3 @@
+{
+
+}

+ 5 - 0
assets/i18n/zh-CN.json

@@ -0,0 +1,5 @@
+{
+  "boss_limit_time": "单局Boss限制时间"
+}
+
+

+ 10 - 0
module/server/home_router.py

@@ -84,3 +84,13 @@ async def chinese_translate(data: dict = Body(...)):
     except Exception as e:
         logger.error(e)
     return True
+
+
+@home_app.get('/additional_translate')
+async def additional_translate() -> dict:
+    try:
+        data = I18n.load_additions()
+        return data
+    except Exception as e:
+        logger.error(e)
+    return {}

+ 16 - 1
module/server/i18n.py

@@ -2,7 +2,22 @@ import json
 from pathlib import Path
 
 
-class I18n:
+class Addition:
+    @classmethod
+    def load_additions(cls) -> dict:
+        result = {}
+        files: str = ['en-US', 'zh-CN']
+        for file in files:
+            file_path = Path.cwd() / 'assets' / 'i18n' / f'{file}.json'
+            result[file] = {}
+            if not file_path.exists():
+                continue
+            with open(str(file_path), 'r', encoding='utf-8') as f:
+                result[file] = json.load(f)
+        return result
+
+
+class I18n(Addition):
     file_zh_cn = Path.cwd() / 'module' / 'config' / 'i18n' / 'zh-CN.json'
 
     @classmethod