type MessageKey = | "colIndex" | "colTitle" | "colChannel" | "colDuration" | "colAddedBy" | "colVotes" | "filterTitle" | "filterChannel" | "filterAddedBy" | "badgeLive" | "headerVideos"; const messages: Record> = { ja: { colIndex: "#", colTitle: "タイトル", colChannel: "チャンネル", colDuration: "長さ", colAddedBy: "追加者", colVotes: "投票", filterTitle: "タイトル検索...", filterChannel: "チャンネル...", filterAddedBy: "追加者...", badgeLive: "ライブ", headerVideos: "本の動画", }, en: { colIndex: "#", colTitle: "Title", colChannel: "Channel", colDuration: "Duration", colAddedBy: "Added by", colVotes: "Votes", filterTitle: "Search title...", filterChannel: "Channel...", filterAddedBy: "Added by...", badgeLive: "LIVE", headerVideos: "videos", }, }; function detectLang(): string { const htmlLang = document.documentElement.lang; if (htmlLang?.startsWith("ja")) return "ja"; return "en"; } export function t(key: MessageKey): string { const lang = detectLang(); return (messages[lang] ?? messages.en)[key]; }