Skip to content

Commit b6a2c4b

Browse files
author
kezhengjie
committed
translate done
1 parent 2cbae73 commit b6a2c4b

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

i18n.py

+16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def __init__(
3131
fail: str,
3232
unable_to_start_grpc_server: str,
3333
title: str,
34+
receiving_file: str,
35+
receive_file_successful: str,
36+
sending_file: str,
37+
syncing_file_to: str,
3438
) -> None:
3539
self.ip_label = ip_label
3640
self.ip_edit_button = ip_edit_button
@@ -62,6 +66,10 @@ def __init__(
6266
self.fail = fail
6367
self.unable_to_start_grpc_server = unable_to_start_grpc_server
6468
self.title = title
69+
self.receiving_file = receiving_file
70+
self.receive_file_successful = receive_file_successful
71+
self.sending_file = sending_file
72+
self.syncing_file_to = syncing_file_to
6573

6674

6775
cn = Text(
@@ -95,6 +103,10 @@ def __init__(
95103
"失败",
96104
"无法启动grpc服务器",
97105
"游戏存档同步工具",
106+
"正在接收文件",
107+
"接收文件成功",
108+
"正在发送文件",
109+
"同步文件到{}中"
98110
)
99111

100112
en = Text(
@@ -128,6 +140,10 @@ def __init__(
128140
"fail",
129141
"unable to start grpc server",
130142
"Game Save Sync",
143+
"receiving file",
144+
"receive file successful",
145+
"sending file",
146+
"syncing file to {}"
131147
)
132148

133149

mainwindow.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Signal(QObject):
3737
class MainWindow(QWidget):
3838
def __init__(self):
3939
super().__init__()
40-
self._debug_mode = True
40+
self._debug_mode = False
4141
self._grpc_client = None
4242
self.config = Config()
4343
self._text: Text = get_i18n_text(self.config.lang)
@@ -67,6 +67,7 @@ def switch_cn_en(self):
6767
self.config.lang = "cn"
6868
self.config.save()
6969
self._text = get_i18n_text(self.config.lang)
70+
self.rpc_service.set_text_source(self._text)
7071
self.i18n()
7172

7273
def _debug_method(self):
@@ -162,10 +163,12 @@ def moveEvent(self, ev: QMoveEvent):
162163
def start_grpc_thread(self):
163164
try:
164165
self.grpc_server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
166+
self.rpc_service = RPCService(
167+
get_filepath=self.filepath_line_edit.text, logger=self.print
168+
)
169+
self.rpc_service.set_text_source(self._text)
165170
rpc_service_pb2_grpc.add_RpcServicer_to_server(
166-
RPCService(
167-
get_filepath=self.filepath_line_edit.text, logger=self.print
168-
),
171+
self.rpc_service,
169172
self.grpc_server,
170173
)
171174
self.grpc_server.add_insecure_port("[::]:" + str(self.config.listen_port))
@@ -223,7 +226,7 @@ def show_ip_edit_dialog(self):
223226

224227
def compress_file(self, filepath: str):
225228
zip_filepath = "temp.zip"
226-
self.print(f"{self._text.compressing}{os.path.basename(filepath)}")
229+
self.print(f"{self._text.compressing} {os.path.basename(filepath)}")
227230
compress_file(filepath, zip_filepath)
228231
self.print(f"{self._text.compress_done}")
229232
return zip_filepath

rpc_service.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import grpc
1010
from compress import compress_file, decompress
11+
from i18n import Text
1112
import rpc_service_pb2
1213
import rpc_service_pb2_grpc
1314
from threading import Thread
@@ -26,6 +27,9 @@ def __init__(self, *args, **kwargs) -> None:
2627
self._get_filepath = kwargs["get_filepath"]
2728
self._logger = kwargs["logger"]
2829

30+
def set_text_source(self, text: Text):
31+
self._text = text
32+
2933
def Ping(self, request, context):
3034
print(request)
3135
return rpc_service_pb2.PingReply(msg="pong")
@@ -53,34 +57,34 @@ def FileStatus(self, request, context):
5357

5458
def UploadFile(self, it, context):
5559
filepath = self._get_filepath()
56-
self._logger(f"正在接收文件{os.path.basename(filepath)}")
60+
self._logger(f"{self._text.receiving_file} {os.path.basename(filepath)}")
5761
zip_filepath = "temp.zip"
5862
with open(zip_filepath, "wb") as fd:
5963
for i in it:
6064
fd.write(i.data)
61-
self._logger(f"接收文件成功")
62-
self._logger(f"正在解压")
65+
self._logger(f"{self._text.receive_file_successful}")
66+
self._logger(f"{self._text.decompressing}")
6367
decompress(zip_filepath, os.path.dirname(filepath))
64-
self._logger(f"解压成功")
68+
self._logger(f"{self._text.decompress_success}")
6569
return rpc_service_pb2.UploadFileReply(status=True)
6670

6771
def DownloadFile(self, request, context):
6872
filepath = self._get_filepath()
69-
self._logger(f"正在压缩{os.path.basename(filepath)}")
73+
self._logger(f"{self._text.compressing} {os.path.basename(filepath)}")
7074
zip_filepath = "temp.zip"
7175
compress_file(filepath, zip_filepath)
72-
self._logger(f"压缩成功")
73-
self._logger(f"发送文件{os.path.basename(filepath)}")
76+
self._logger(f"{self._text.compress_done}")
77+
self._logger(f"{self._text.sending_file} {os.path.basename(filepath)}")
7478
with open(zip_filepath, "rb") as fd:
7579
while True:
7680
data = fd.read(BUF_SIZE)
7781
if len(data) <= 0:
78-
self._logger(f"发送文件成功")
82+
self._logger(f"{self._text.send_success}")
7983
return
8084
yield rpc_service_pb2.DownloadFileReply(data=data)
8185

8286
def DownloadDirectory(self, request, context):
83-
self._logger("正在发送文件到远端")
87+
self._logger(f"{self._text.sending_file_to_remote}")
8488
directory_path = self._get_filepath()
8589
with zipfile.ZipFile("temp.zip", "w", zipfile.ZIP_DEFLATED) as zip:
8690
for file in request.files:
@@ -92,21 +96,21 @@ def DownloadDirectory(self, request, context):
9296
while True:
9397
data = fd.read(BUF_SIZE)
9498
if len(data) <= 0:
95-
self._logger(f"发送文件成功")
99+
self._logger(f"{self._text.send_success}")
96100
return
97101
yield rpc_service_pb2.DownloadDirectoryReply(data=data)
98102

99103
def ReceiveDirectory(self, request, context):
100104
dir_path = self._get_filepath()
101-
self._logger(f"同步文件到{dir_path}中")
105+
self._logger(self._text.syncing_file_to.format(dir_path))
102106
zip_filepath = "temp.zip"
103107
with open(zip_filepath, "wb") as fd:
104108
for i in request:
105109
fd.write(i.data)
106-
self._logger("正在解压")
110+
self._logger(f"{self._text.decompressing}")
107111
decompress("temp.zip", dir_path)
108-
self._logger("解压成功")
109-
self._logger("同步成功")
112+
self._logger(f"{self._text.decompress_success}")
113+
self._logger(f"{self._text.sync_success}")
110114
return rpc_service_pb2.ReceiveDirectoryReply()
111115

112116
def DirectoryStatus(self, request, context):

0 commit comments

Comments
 (0)