Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
feat(i18n): 🌐 add i18n for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jul 2, 2022
1 parent c76cd4e commit 571923e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
11 changes: 11 additions & 0 deletions lang/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
11 changes: 11 additions & 0 deletions lang/zh-cn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
42 changes: 30 additions & 12 deletions utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand All @@ -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):
Expand Down Expand Up @@ -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 = ''
Expand All @@ -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'])
)
)

# 弹窗提示
Expand Down

0 comments on commit 571923e

Please sign in to comment.