$path, 'filename' => $filename, 'ascii_fallback' => $asciiFallback, 'lang' => $lang, ]; } public static function resolveLang(Request $request): string { $thinkRaw = $request->header('think-lang', ''); $thinkLang = is_string($thinkRaw) ? trim($thinkRaw) : ''; if ($thinkLang === '' && is_array($thinkRaw) && isset($thinkRaw[0]) && is_string($thinkRaw[0])) { $thinkLang = trim($thinkRaw[0]); } $queryRaw = $request->get('lang'); if ($queryRaw === null || $queryRaw === '') { $queryRaw = $request->post('lang'); } $queryLang = is_string($queryRaw) ? trim($queryRaw) : (is_scalar($queryRaw) ? trim(strval($queryRaw)) : ''); $headerRaw = $request->header('lang', ''); $headerLang = is_string($headerRaw) ? trim($headerRaw) : ''; $normalize = static function (string $raw): string { $s = str_replace('_', '-', strtolower(trim($raw))); if ($s === 'zh') { return 'zh-cn'; } return $s; }; foreach ([$thinkLang, $headerLang, $queryLang] as $candidate) { if ($candidate === '') { continue; } $normalized = $normalize($candidate); if ($normalized === 'en') { return 'en'; } if ($normalized === 'zh-cn') { return 'zh-cn'; } } return 'zh-cn'; } }