From 571923e5921b0ccfe34ddf308a7ff697e094b631 Mon Sep 17 00:00:00 2001 From: Andy Zhang <37402126+AnzhiZhang@users.noreply.github.com> Date: Sat, 2 Jul 2022 20:24:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(i18n):=20=F0=9F=8C=90=20add=20i18n=20for?= =?UTF-8?q?=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lang/en-us.yaml | 11 +++++++++++ lang/zh-cn.yaml | 11 +++++++++++ utils/download.py | 42 ++++++++++++++++++++++++++++++------------ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/lang/en-us.yaml b/lang/en-us.yaml index 9a8a5ef..2acc13b 100644 --- a/lang/en-us.yaml +++ b/lang/en-us.yaml @@ -28,3 +28,14 @@ download.getModWarning.title: Warning download.getModWarning.content: | {0} Please get more info in log. +download.logging.unzipped: Unzipped files +download.logging.foundMods: '{0} mods were found' +download.logging.gotDownloadURL: 'Got mod download URL ({0}/{1}): {2}' +download.logging.gotMod: 'Got mod ({0}/{1}): {2}' +download.logging.success: Successfully downloaded {0} +download.logging.downloadFail: | + {0} mods download failed, please download them manually: + {1} +download.logging.verifyFail: | + {0} mods verify failed, generally not manually download required: + {1} diff --git a/lang/zh-cn.yaml b/lang/zh-cn.yaml index 870dc68..5868bad 100644 --- a/lang/zh-cn.yaml +++ b/lang/zh-cn.yaml @@ -28,3 +28,14 @@ download.getModWarning.title: 警告 download.getModWarning.content: | {0} 请查看日志获取详细信息。 +download.logging.unzipped: 文件已解压 +download.logging.foundMods: 已找到 {0} 个模组 +download.logging.gotDownloadURL: 获取模组下载链接({0}/{1}):{2} +download.logging.gotMod: 下载模组({0}/{1}):{2} +download.logging.success: 成功下载 {0} +download.logging.downloadFail: | + {0} 个模组下载失败,请手动下载: + {1} +download.logging.verifyFail: | + {0} 个模组校验失败,一般无需手动下载: + {1} diff --git a/utils/download.py b/utils/download.py index 7d9ceb2..a21daaa 100644 --- a/utils/download.py +++ b/utils/download.py @@ -93,7 +93,9 @@ def run(): # 解压文件 self.unzip() - self.logger.info('Unzipped files') + self.logger.info( + self.factory.language.translate('download.logging.unzipped') + ) # 设置进度条 pb['maximum'] = self.mod_count * 2 @@ -148,8 +150,10 @@ def clear(): self.factory.language.translate('download.finish.content') ) self.factory.logger.info( - 'Successfully downloaded %s', - self.name + self.factory.language.translate( + 'download.logging.success', + self.name + ) ) Thread(target=run, name='Download').start() @@ -170,7 +174,9 @@ def get_download_urls(self, update: Callable): files = data['files'] count = len(files) - self.logger.info('%d mods were found', count) + self.logger.info( + self.factory.language.translate('download.logging.foundMods', count) + ) result = [] i = 0 for r in self.thread_pool.map( @@ -188,9 +194,12 @@ def get_download_urls(self, update: Callable): data['fileName'] ) result.append(url) - self.logger.info(f'获取模组下载链接({i}/{count})') - if self.logger.debug_mode: - self.logger.debug(f'Got mod download url: %s', url) + self.logger.info( + self.factory.language.translate( + 'download.logging.gotDownloadURL', + i, count, url + ) + ) return result def download_mods(self, urls, update: Callable): @@ -241,7 +250,12 @@ def download(url): for name in self.thread_pool.map(download, urls): i += 1 update() - self.logger.info(f'下载模组({i}/{count}):{name}') + self.logger.info( + self.factory.language.translate( + 'download.logging.gotMod', + i, count, name + ) + ) # 提示结果 warning_text = '' @@ -254,16 +268,20 @@ def download(url): failed_download_count ) self.logger.error( - f'{failed_download_count} 个模组下载失败,请手动下载:\n' + - '\n'.join(failed_mods['download']) + self.factory.language.translate( + 'download.logging.downloadFail', + failed_download_count, '\n'.join(failed_mods['download']) + ) ) # 验证失败日志 failed_verify_count = len(failed_mods['verify']) if failed_verify_count > 0: self.logger.warning( - f'{failed_verify_count} 个模组校验失败,一般无需手动下载:\n' + - '\n'.join(failed_mods['verify']) + self.factory.language.translate( + 'download.logging.verifyFail', + failed_verify_count, '\n'.join(failed_mods['verify']) + ) ) # 弹窗提示