From b4a619cb6170c359998f1c1de812f916b85f8b0d Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Thu, 4 Jul 2024 12:04:41 +0800 Subject: [PATCH] finish translation --- lilac2/api.py | 5 ++-- lilac2/building.py | 9 ++++-- lilac2/cmd.py | 4 ++- lilac2/l10n/en/mail.ftl | 41 +++++++++++++++++++++++++++ lilac2/l10n/en/main.ftl | 3 ++ lilac2/l10n/zh_CN/mail.ftl | 41 +++++++++++++++++++++++++++ lilac2/l10n/zh_CN/main.ftl | 3 ++ lilac2/mail.py | 5 +++- lilac2/nvchecker.py | 9 ++++-- lilac2/repo.py | 58 +++++++++++++++++++++++++------------- lilac2/worker.py | 20 +++++++++---- 11 files changed, 163 insertions(+), 35 deletions(-) diff --git a/lilac2/api.py b/lilac2/api.py index 31bcc494..6bb4ce7e 100644 --- a/lilac2/api.py +++ b/lilac2/api.py @@ -24,7 +24,7 @@ from .cmd import git_pull, git_push, UNTRUSTED_PREFIX from .cmd import run_cmd as _run_cmd -from . import const +from . import const, intl from .const import _G, SPECIAL_FILES from .typing import PkgRel, Cmd from .pypi2pkgbuild import gen_pkgbuild @@ -421,10 +421,11 @@ def update_aur_repo() -> None: try: _update_aur_repo_real(pkgbase) except subprocess.CalledProcessError as e: + l10n = intl.get_l10n('mail') _G.repo.send_error_report( _G.mod, exc = e, - subject = '提交软件包 %s 到 AUR 时出错', + subject = l10n.format_value('aur-submit-error'), ) def git_pkgbuild_commit() -> None: diff --git a/lilac2/building.py b/lilac2/building.py index 9a55a8a7..cfad356e 100644 --- a/lilac2/building.py +++ b/lilac2/building.py @@ -21,6 +21,7 @@ from .tools import reap_zombies from .nomypy import BuildResult # type: ignore from . import systemd +from . import intl if TYPE_CHECKING: from .repo import Repo @@ -91,10 +92,14 @@ def build_package( destdir.mkdir() sign_and_copy(pkgdir, destdir) if staging: + l10n = intl.get_l10n('mail') notify_maintainers( repo, lilacinfo, - f'{pkgbase} {pkg_version} 刚刚打包了', - '软件包已被置于 staging 目录,请查验后手动发布。', + l10n.format_value('package-staged-subject', { + 'pkg': pkgbase, + 'version': pkg_version, + }), + l10n.format_value('package-staged-body'), ) result = BuildResult.staged() else: diff --git a/lilac2/cmd.py b/lilac2/cmd.py index bf5a4833..28cb008f 100644 --- a/lilac2/cmd.py +++ b/lilac2/cmd.py @@ -13,6 +13,7 @@ from contextlib import suppress from .typing import Cmd +from . import intl logger = logging.getLogger(__name__) @@ -148,7 +149,8 @@ def child_exited(signum: int, sigframe: Optional[types.FrameType]) -> None: outs = outs.replace('\r\n', '\n') outs = re.sub(r'.*\r', '', outs) if outlen > 1024 ** 3: # larger than 1G - outs += '\n\n输出过多,已击杀。\n' + l10n = intl.get_l10n('mail') + outs += '\n\n' + l10n.format_value('too-much-output') + '\n' if code != 0: # set output by keyword to avoid being included in repr() raise subprocess.CalledProcessError(code, cmd, output=outs) diff --git a/lilac2/l10n/en/mail.ftl b/lilac2/l10n/en/mail.ftl index 07d44bc0..cfb23379 100644 --- a/lilac2/l10n/en/mail.ftl +++ b/lilac2/l10n/en/mail.ftl @@ -18,3 +18,44 @@ dependency-issue-failed-this-batch = {$count_deps -> [one] { $faileddeps } has *[other] { $faileddeps } have } failed this time. + +aur-submit-error = Failed to submit %s to AUR + +package-staged-subject = { $pkg } { $version } has been packaged just now +package-staged-body = The package has been placed in the staging directory, please check it and then publish manually. + +too-much-output = Too much output, killed. + +log-too-long = Log too long, omitting... + +nvchecker-error-report = nvchecker error report + +github-token-not-set = github token not configured, unable to retrieve Email address from GitHub +github-email-error = Error retrieving maintainer's Email address from GitHub: { $error } +github-email-private = GitHub user { $user } doesn't make their Email address public +unsupported-maintainer-info = Unsupported format: { $info } + +maintainers-error-subject = maintainers for { $pkg } has errors +maintainers-error-body = The following maintainers information has errors, please fix: + +packaging-error-subprocess-subject = Error packaging %s +packaging-error-subprocess = + Command failed! + + Command { $cmd } returned error code { $returncode }. +packaging-error-subprocess-output = Output of the command follows: +packaging-error-traceback = Traceback: +packaging-error-aur-subject = Error retrieving AUR package +packaging-error-aur = Failed to retrieve AUR package! +packaging-error-timeout-subject = Timeout when packaging %s +packaging-error-unknown-subject = Unknown error when packaging %s +packaging-error-unknown = An unknown error happend! +packaging-log = Packaging log: + +lilac-yaml-loadding-error = Failed to load lilac.yaml for %s + +package-in-official-group = Packages is added to official groups: { $groups }{ "\n" } +package-replacing-official-package = Package is replacing official packages: { $packages }{ "\n" } +package-conflicts-with-official-repos = %s conflicts with official repos +package-older-subject = Built package %s has an older version than the one in repo +package-older-body = Package { $pkg } built as version { $built_version }, but there is a version { $repo_version } in repo already.{ "\n" } diff --git a/lilac2/l10n/en/main.ftl b/lilac2/l10n/en/main.ftl index fa38b406..46c9414c 100644 --- a/lilac2/l10n/en/main.ftl +++ b/lilac2/l10n/en/main.ftl @@ -1,2 +1,5 @@ runtime-error = Runtime error runtime-error-traceback = Traceback follows: + +nvchecker-issues-subject = nvchecker issues +nvchecker-issues-body = There are some errors while running nvchecker: diff --git a/lilac2/l10n/zh_CN/mail.ftl b/lilac2/l10n/zh_CN/mail.ftl index ef21b9c0..f6b2c4b0 100644 --- a/lilac2/l10n/zh_CN/mail.ftl +++ b/lilac2/l10n/zh_CN/mail.ftl @@ -6,3 +6,44 @@ update_on_build-error = %s update_on_build 检查出错 dependency-issue-subject = %s 出现依赖问题 dependency-issue-failed = { $pkg } 的依赖 { $faileddeps } 打包失败了。 dependency-issue-failed-this-batch = { $pkg } 缺少依赖 { $deps },其中 { $faileddeps } 本次打包失败了。 + +aur-submit-error = 提交软件包 %s 到 AUR 时出错 + +package-staged-subject = { $pkg } { $version } 刚刚打包了 +package-staged-body = 软件包已被置于 staging 目录,请查验后手动发布。 + +too-much-output = 输出过多,已击杀。 + +log-too-long = 日志过长,省略ing…… + +nvchecker-error-report = nvchecker 错误报告 + +github-token-not-set = 未设置 github token,无法从 GitHub 取得用户 Email 地址 +github-email-error = 从 GitHub 获取维护者 Email 地址时出错:{ $error } +github-email-private = GitHub 用户 { $user } 未公开 Email 地址 +unsupported-maintainer-info = 不支持的格式:{ $info } + +maintainers-error-subject = { $pkg } 的 maintainers 信息有误 +maintainers-error-body = 以下 maintainers 信息有误,请修正。 + +packaging-error-subprocess-subject = 在打包软件包 %s 时发生错误 +packaging-error-subprocess = + 命令执行失败! + + 命令 { $cmd } 返回了错误号 { $returncode }。 +packaging-error-subprocess-output = 命令的输出如下: +packaging-error-traceback = 调用栈如下: +packaging-error-aur-subject = 在获取AUR包 %s 时发生错误 +packaging-error-aur = 获取AUR包失败! +packaging-error-timeout-subject = 打包软件包 %s 超时 +packaging-error-unknown-subject = 在打包软件包 %s 时发生未知错误 +packaging-error-unknown = 发生未知错误! +packaging-log = 打包日志: + +lilac-yaml-loadding-error = 为软件包 %s 载入 lilac.yaml 时失败 + +package-in-official-group = 软件包被加入了官方组:{ $groups }{ "\n" } +package-replacing-official-package = 软件包将取代官方包:{ $packages }{ "\n" } +package-conflicts-with-official-repos = %s 与官方软件库冲突 +package-older-subject = %s 新打的包比仓库里的包旧 +package-older-body = 包 { $pkg } 打的版本为 { $built_version },但在仓库里已有较新版本 { $repo_version }。{ "\n" } diff --git a/lilac2/l10n/zh_CN/main.ftl b/lilac2/l10n/zh_CN/main.ftl index 9eebe00b..0985d353 100644 --- a/lilac2/l10n/zh_CN/main.ftl +++ b/lilac2/l10n/zh_CN/main.ftl @@ -1,2 +1,5 @@ runtime-error = 运行时错误 runtime-error-traceback = 调用栈如下: + +nvchecker-issues-subject = nvchecker 问题 +nvchecker-issues-body = 在更新检查时出现了一些错误: diff --git a/lilac2/mail.py b/lilac2/mail.py index 28a54764..469c327b 100644 --- a/lilac2/mail.py +++ b/lilac2/mail.py @@ -4,6 +4,7 @@ from typing import Union, Type, List, Dict, Any from .vendor.mailutils import assemble_mail +from . import intl SMTPClient = Union[smtplib.SMTP, smtplib.SMTP_SSL] @@ -44,7 +45,9 @@ def sendmail(self, to: Union[str, List[str]], s = self.smtp_connect() if len(msg) > 5 * 1024 ** 2: - msg = msg[:1024 ** 2] + '\n\n日志过长,省略ing……\n\n' + \ + l10n = intl.get_l10n('mail') + too_long = l10n.format_value('log-too-long') + msg = msg[:1024 ** 2] + '\n\n' + too_long + '\n\n' + \ msg[-1024 ** 2:] mail = assemble_mail('[%s] %s' % ( self.mailtag, subject), to, self.from_, text=msg) diff --git a/lilac2/nvchecker.py b/lilac2/nvchecker.py index 3a588e50..3dd04f82 100644 --- a/lilac2/nvchecker.py +++ b/lilac2/nvchecker.py @@ -18,6 +18,7 @@ from .const import mydir from .typing import LilacInfos, PathLike from .tools import reap_zombies +from . import intl if TYPE_CHECKING: from .repo import Repo, Maintainer @@ -177,15 +178,17 @@ def packages_need_update( 'event': 'wrong or missing `update_on` config', }) + l10n = intl.get_l10n('mail') for who, their_errors in error_owners.items(): logger.warning('send nvchecker report for %r packages to %s', {x['name'] for x in their_errors}, who) - repo.sendmail(who, 'nvchecker 错误报告', + repo.sendmail(who, l10n.format_value('nvchecker-error-report'), '\n'.join(_format_error(e) for e in their_errors)) if None in errors: # errors belong to unknown packages - subject = 'nvchecker 问题' - msg = '在更新检查时出现了一些错误:\n\n' + '\n'.join( + l10n = intl.get_l10n('main') + subject = l10n.format_value('nvchecker-issues-subject') + msg = l10n.format_value('nvchecker-issues-body') + '\n\n' + '\n'.join( _format_error(e) for e in errors[None]) + '\n' repo.send_repo_mail(subject, msg) diff --git a/lilac2/repo.py b/lilac2/repo.py index 225dca7c..65107502 100644 --- a/lilac2/repo.py +++ b/lilac2/repo.py @@ -19,7 +19,7 @@ from .mail import MailService from .tools import ansi_escape_re -from . import api, lilacyaml +from . import api, lilacyaml, intl from .typing import LilacMod, Maintainer, LilacInfos, LilacInfo from .nomypy import BuildResult # type: ignore if TYPE_CHECKING: @@ -62,7 +62,9 @@ def __init__(self, config: dict[str, Any]) -> None: @lru_cache() def maintainer_from_github(self, username: str) -> Optional[Maintainer]: if self.gh is None: - raise ValueError('未设置 github token,无法从 GitHub 取得用户 Email 地址') + l10n = intl.get_l10n('mail') + msg = l10n.format_value('github-token-not-set') + raise ValueError(msg) userinfo = self.gh.get_user_info(username) if userinfo['email']: @@ -77,6 +79,7 @@ def parse_maintainers( ret = [] errors = [] + l10n = intl.get_l10n('mail') for m in ms: if 'github' in m and 'email' in m: ret.append( @@ -86,15 +89,18 @@ def parse_maintainers( try: u = self.maintainer_from_github(m['github']) except Exception as e: - errors.append(f'从 GitHub 获取用户 Email 地址时出错:{e!r}') + msg = l10n.format_value('github-email-error', {'error': repr(e)}) + errors.append(msg) else: if u is None: - errors.append(f'GitHub 用户 {m["github"]} 未公开 Email 地址') + msg = l10n.format_value('github-email-private', {'user': m['github']}) + errors.append(msg) else: ret.append(u) else: logger.error('unsupported maintainer info: %r', m) - errors.append(f'不支持的格式:{m!r}') + msg = l10n.format_value('unsupported-maintainer-info', {'info': repr(m)}) + errors.append(msg) continue return ret, errors @@ -190,10 +196,11 @@ def _find_maintainers_impl( if errors: error_str = '\n'.join(errors) + l10n = intl.get_l10n('mail') self.sendmail( git_maintainer, - subject = f'{pkgbase} 的 maintainers 信息有误', - msg = f"以下 maintainers 信息有误,请修正。\n\n{error_str}\n", + subject = l10n.format_value('maintainers-error-subject', {'pkg': pkgbase}), + msg = l10n.format_value('maintainers-error-body') + f'\n\n{error_str}\n', ) if not ret and fallback_git: @@ -262,24 +269,34 @@ def send_error_report( if msg is not None: msgs.append(msg) + l10n = intl.get_l10n('mail') + if exc is not None: tb = ''.join(traceback.format_exception(type(exc), exc, exc.__traceback__)) if isinstance(exc, subprocess.CalledProcessError): - subject_real = subject or '在打包软件包 %s 时发生错误' - msgs.append('命令执行失败!\n\n命令 %r 返回了错误号 %d。' % ( - exc.cmd, exc.returncode)) + subject_real = subject or l10n.format_value('packaging-error-subproces-subject') + msg1 = l10n.format_value('packaging-error-subprocess', { + 'cmd': repr(exc.cmd), + 'returncode': exc.returncode, + }) + msgs.append(msg1) if exc.output: - msgs.append('命令的输出如下:\n\n%s' % exc.output) - msgs.append('调用栈如下:\n\n' + tb) + msg1 = l10n.format_value('packaging-error-subprocess-output') + msgs.append(msg1 + '\n\n' + exc.output) + msg1 = l10n.format_value('packaging-error-traceback') + msgs.append(msg1 + '\n\n' + tb) elif isinstance(exc, api.AurDownloadError): - subject_real = subject or '在获取AUR包 %s 时发生错误' - msgs.append('获取AUR包失败!\n\n') - msgs.append('调用栈如下:\n\n' + tb) + subject_real = subject or l10n.format_value('packaging-error-aur-subject') + msg1 = l10n.format_value('packaging-error-aur') + msgs.append(msg1 + '\n\n') + msg1 = l10n.format_value('packaging-error-traceback') + msgs.append(msg1 + '\n\n' + tb) elif isinstance(exc, TimeoutError): - subject_real = subject or '打包软件包 %s 超时' + subject_real = subject or l10n.format_value('packaging-error-timeout-subject') else: - subject_real = subject or '在打包软件包 %s 时发生未知错误' - msgs.append('发生未知错误!调用栈如下:\n\n' + tb) + subject_real = subject or l10n.format_value('packaging-error-unknown-subject') + msg1 = l10n.format_value('packaging-error-unknown') + l10n.format_value('packaging-error-traceback') + msgs.append(msg1 + '\n\n' + tb) else: if subject is None: raise ValueError('subject should be given but not') @@ -295,7 +312,7 @@ def send_error_report( with logfile.open(errors='replace') as f: build_output = f.read() if build_output: - log_header = '打包日志:' + log_header = l10n.format_value('packaging-log') with suppress(ValueError, KeyError): # invalid template or wrong key if self.logurl_template and len(logfile.parts) >= 2: # assume the directory name is the time stamp for now. @@ -332,13 +349,14 @@ def manages(self, dep: Dependency) -> bool: def load_managed_lilac_and_report(self) -> dict[str, tuple[str, ...]]: self.lilacinfos, errors = lilacyaml.load_managed_lilacinfos(self.repodir) failed: dict[str, tuple[str, ...]] = {p: () for p in errors} + l10n = intl.get_l10n('mail') for name, exc_info in errors.items(): logger.error('error while loading lilac.yaml for %s', name, exc_info=exc_info) exc = exc_info[1] if not isinstance(exc, Exception): raise self.send_error_report(name, exc=exc, - subject='为软件包 %s 载入 lilac.yaml 时失败') + subject=l10n.format_value('lilac-yaml-loadding-error')) build_logger_old.error('%s failed', name) build_logger.exception('lilac.yaml error', pkgbase = name, exc_info=exc_info) diff --git a/lilac2/worker.py b/lilac2/worker.py index c8b0030f..1b033d2e 100644 --- a/lilac2/worker.py +++ b/lilac2/worker.py @@ -29,6 +29,7 @@ from .lilacyaml import load_lilacinfo from .const import _G, PACMAN_DB_DIR, mydir from .repo import Repo +from . import intl logger = logging.getLogger(__name__) @@ -195,7 +196,7 @@ def run_build_cmd(cmd: Cmd) -> None: st = os.stat(1) if st.st_size > 1024 ** 3: # larger than 1G kill_child_processes() - logger.error('\n\n输出过多,已击杀。') + logger.error('\n\nToo much output, killed.') else: if code != 0: raise subprocess.CalledProcessError(code, cmd) @@ -260,21 +261,28 @@ def handle_failure( e: Exception, repo: Repo, mod: Union[LilacMod, LilacInfo], logfile: Path, ) -> None: logger.error('build failed', exc_info=e) + l10n = intl.get_l10n('mail') if isinstance(e, pkgbuild.ConflictWithOfficialError): reason = '' if e.groups: - reason += f'软件包被加入了官方组:{e.groups}\n' + reason += l10n.format_value('package-in-official-group', {'groups': repr(e.groups)}) if e.packages: - reason += f'软件包将取代官方包:{e.packages}\n' + reason += l10n.format_value('package-replacing-official-package', {'packages': repr(e.packages)}) + subj = l10n.format_value('package-conflicts-with-official-repos') repo.send_error_report( - mod, subject='%s 与官方软件库冲突', msg = reason, + mod, subject = subj, msg = reason, ) elif isinstance(e, pkgbuild.DowngradingError): repo.send_error_report( - mod, subject='%s 新打的包比仓库里的包旧', - msg=f'包 {e.pkgname} 打的版本为 {e.built_version},但在仓库里已有较新版本 {e.repo_version}。\n', + mod, + subject = l10n.format_value('package-older-subject'), + msg = l10n.format_value('package-older-body', { + 'pkg': e.pkgname, + 'built_version': e.built_version, + 'repo_version': e.repo_version, + }), ) else: