From d3ee3faec4258bb14f57d873a7070ca8ad3b5ffd Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Wed, 8 Apr 2026 17:37:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8A=BD=E5=A5=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3/api/game/playStart=E7=BF=BB=E8=AF=91=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/api/util/ApiLang.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/server/app/api/util/ApiLang.php b/server/app/api/util/ApiLang.php index 74740f7..54f5ebb 100644 --- a/server/app/api/util/ApiLang.php +++ b/server/app/api/util/ApiLang.php @@ -62,6 +62,17 @@ class ApiLang return (string) $map[$key]; } + // 兼容旧版:历史代码直接抛中文 message,lang=en 时从 legacy_en.php 映射到英文 + if ($lang === self::LANG_EN) { + $legacy = self::loadLegacyEnMessages(); + if (isset($legacy[$message])) { + return (string) $legacy[$message]; + } + if ($key !== null && isset($legacy[$key])) { + return (string) $legacy[$key]; + } + } + return $message; } @@ -108,6 +119,22 @@ class ApiLang return 'MSG_' . strtoupper(sprintf('%08X', crc32($trim))); } + /** + * 加载中文原文 => 英文 的兼容映射(仅 lang=en 使用) + * @return array + */ + private static function loadLegacyEnMessages(): array + { + $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'legacy_en.php'; + if (is_file($path)) { + $data = require $path; + if (is_array($data)) { + return $data; + } + } + return []; + } + /** * 带占位符的翻译,如 translateParams('当前玩家余额%s小于%s无法继续游戏', [$coin, $minCoin]) * 先翻译再替换(en 文案使用 %s 占位)