From cf9373e5c2bb235b574f05f84d0c0dff59c1c967 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Mon, 20 Apr 2026 10:33:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=87=E6=8D=A2=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E6=97=B6=E8=8F=9C=E5=8D=95=E4=B8=8D=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/library/Auth.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/admin/library/Auth.php b/app/admin/library/Auth.php index 8cdd831..62a9def 100644 --- a/app/admin/library/Auth.php +++ b/app/admin/library/Auth.php @@ -278,25 +278,29 @@ class Auth extends \ba\Auth public function getMenus(int $uid = 0): array { $menus = parent::getMenus($uid ?: $this->id); + // 库内 title 为中文;仅英文界面走 __()。若对 zh-cn 也 __(),Symfony 在找不到键时会 fallback 到 en, + // 命中 admin_rule_title 后会把中文标题误译成英文。 + $localeNorm = str_replace('_', '-', strtolower(locale())); + $toEnglish = ($localeNorm === 'en'); - return $this->translateMenuRuleTitles($menus); + return $this->translateMenuRuleTitles($menus, $toEnglish); } /** - * 将 admin_rule.title(库内中文等)按当前请求语言翻译,供侧边栏/标签与 meta.title 一致。 - * 英文词条见 app/common/lang/en/admin_rule_title.php + * 将 admin_rule.title 在英文界面译为英文;中文界面保持库内原文。 + * 英文映射见 app/common/lang/en/admin_rule_title.php * * @param array> $menus * @return array> */ - private function translateMenuRuleTitles(array $menus): array + private function translateMenuRuleTitles(array $menus, bool $toEnglish): array { foreach ($menus as $k => $item) { if (isset($item['title']) && is_string($item['title']) && $item['title'] !== '') { - $menus[$k]['title'] = __($item['title']); + $menus[$k]['title'] = $toEnglish ? __($item['title']) : $item['title']; } if (!empty($item['children']) && is_array($item['children'])) { - $menus[$k]['children'] = $this->translateMenuRuleTitles($item['children']); + $menus[$k]['children'] = $this->translateMenuRuleTitles($item['children'], $toEnglish); } }