/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ // 界面语言码归一化——全站唯一入口。 // // 以前一律 split('-')[0] 取主语言,但繁体中文与简体共用主语言 zh,只能靠 // 地区/书写系统子标签区分:zh-TW / zh-HK / zh-MO / zh-Hant-* 归到 'zh-TW' // (繁体包),zh-CN / zh-SG / zh-Hans-* / 裸 zh 归到 'zh'。其余语言仍取主语言, // 这样历史缓存里的 en-US / ko-KR 之类照旧命中各自的语言包。 export const normalizeLanguage = (lng) => { if (!lng) return 'zh'; const parts = String(lng).replace(/_/g, '-').toLowerCase().split('-'); const base = parts[0]; if (base !== 'zh') return base; const subtags = parts.slice(1); if (subtags.includes('hant')) return 'zh-TW'; if (subtags.includes('hans')) return 'zh'; if (subtags.some((s) => s === 'tw' || s === 'hk' || s === 'mo')) { return 'zh-TW'; } return 'zh'; };