mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:19:26 +08:00
Set message-scoped lang from the reply language and add :lang(ja/ko/zh-Hant) font stacks so Japanese/Korean/Traditional Chinese replies no longer fall through to SimSun/Songti SC. Leave the shared SC-first Tailwind stacks alone.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
/**
|
|
* Map a reply-language code onto the HTML ``lang`` value used for assistant
|
|
* message content. Only CJK reply languages get an explicit tag: the shared
|
|
* font stacks in ``tailwind.config.js`` deliberately lead with Simplified
|
|
* Chinese faces, so a ``ja``/``ko``/``zh-tw`` reply rendered under them picks
|
|
* up Simplified glyph forms (SimSun even answers for kana). Pinning the
|
|
* script/region lets the ``:lang()`` stacks in ``globals.css`` put the
|
|
* region-correct faces first while ``zh``/``en`` keep the default stacks.
|
|
* Everything else returns ``undefined`` so the app shell's own ``lang``
|
|
* keeps applying.
|
|
*/
|
|
export function contentLang(
|
|
language: string | undefined,
|
|
): string | undefined {
|
|
const code = language?.trim().toLowerCase().replaceAll("_", "-");
|
|
if (!code) return undefined;
|
|
if (code === "ja" || code === "jp" || code.startsWith("ja-")) return "ja";
|
|
if (code === "ko" || code === "kr" || code.startsWith("ko-")) return "ko";
|
|
if (
|
|
code === "zh-tw" ||
|
|
code === "zh-hant" ||
|
|
code === "zh-hk" ||
|
|
code === "zh-mo" ||
|
|
code.startsWith("zh-hant-") ||
|
|
code.startsWith("zh-tw-")
|
|
) {
|
|
return "zh-Hant";
|
|
}
|
|
if (code === "zh" || code.startsWith("zh-")) return "zh-Hans";
|
|
return undefined;
|
|
}
|