yt-playlist-features/src/content/ui/i18n.ts
2026-04-09 02:28:44 +09:00

53 lines
1.2 KiB
TypeScript

type MessageKey =
| "colIndex"
| "colTitle"
| "colChannel"
| "colDuration"
| "colAddedBy"
| "colVotes"
| "filterTitle"
| "filterChannel"
| "filterAddedBy"
| "badgeLive"
| "headerVideos";
const messages: Record<string, Record<MessageKey, string>> = {
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];
}