import { useSyncExternalStore } from "react" import type { Rel } from "@/lib/types" /** * English and Chinese copy. The language comes from `?lang=zh|en`, then the visitor's last * choice, then the browser's first language; switching re-renders the whole page (App keys it on * the language), so components read `T` while they render and nothing caches copy at import. * Every key must exist in both languages: `zh` is typed from `en`, so a missing one fails the build. * In Chinese, as in English, MiniMax's weights are never called open source: 公开 / 开放权重. */ export type Lang = "en" | "zh" const en = { site: "MiniMax Ecosystem", pageTitle: (name: string) => `${name} · MiniMax Ecosystem`, noData: "The data did not load. Try refreshing the page.", broken: "Something went wrong. Try refreshing the page.", menu: "Models", elsewhere: "Elsewhere", officialLink: (label: string) => `${label} on minimax.io`, hfOrg: "MiniMaxAI on Hugging Face", otherLang: "中文", switchLang: "切换到中文", // the landing page dlTagline: "downloads of MiniMax models and their community", chart: "Chart", metricModels: "Models", metricDownloads: "Downloads", chartModelsAria: (v: string) => `Community models built on MiniMax, ${v} today`, chartDownloadsAria: (v: string) => `Downloads of MiniMax models and everything built on them, ${v} in all`, communityModels: "community models", communityDownloads: "community downloads", minimaxModelDownloads: "MiniMax model downloads", minimaxDownloads: "MiniMax downloads", builders: "builders", openModels: (n: number): string => (n === 1 ? "open model" : "open models"), moreBuilders: (n: string) => `+${n} more builders`, byModality: "By modality", everyRelease: "Every release", earlier: "Earlier releases", later: "Later releases", railCommunity: "community", railDownloads: "downloads", // a model's page heroCount: "community models", // after the number communityDownloads30: "community downloads, 30 days", releaseDownloads: (name: string) => `${name} downloads`, growth: "Growth", byTypeOverTime: "Community models by type", newEachWeek: "New each week", newN: "New", weekOf: (d: string) => `Week of ${d}`, downloadsOverTime: "Downloads over time", dailyDownloads: "Daily downloads", byType: "By type", whoBuilds: "Who builds on it", topModels: "Most downloaded, last 30 days", topBuilders: "Most active builders", allModels: "All community models", galaxy: "Galaxy", // tables and lists type: "Type", model: "Model", modelsCol: "Models", onHfTree: "On HF model tree", dl30Col: "Downloads, 30 days", allTime: "All-time", days30: "30 days", lastDay: "Last day", subtotal: "Subtotal", total: "Total", modelsUnit: (n: number): string => (n === 1 ? "model" : "models"), // after the number search: "Search models or builders", showMore: (n: number) => `Show ${n} more`, // the galaxy rings: ["", "Built on it directly", "Second generation", "Third generation and on"], builtOn: "Built on", downloads: "Downloads", last30: "Last 30 days", likes: "Likes", created: "Created", officialTag: (name: string) => `${name} (official)`, minimaxOfficial: "MiniMax official", galaxyCommunity: "Community models", placing: (n: string) => `Placing ${n} models…`, galaxyAria: (n: string, name: string) => `${n} community models around ${name}`, downloadPng: "Download PNG", downloadAria: (name: string) => `Download ${name} as PNG`, rel: { adapter: "Adapters", finetune: "Fine-tunes", quantized: "Quantized", repackage: "Repackaged", merge: "Merges", mirror: "Mirrors", component: "Components", } as Record, /** English names come from the data (site.json); a key missing here falls back to them. */ cat: {} as Record, } const zh: typeof en = { site: "MiniMax 生态", pageTitle: (name) => `${name} · MiniMax 生态`, noData: "数据没有加载出来,请刷新页面重试。", broken: "页面出错了,请刷新重试。", menu: "模型", elsewhere: "其他链接", officialLink: (label) => `官网 ${label}`, hfOrg: "Hugging Face 上的 MiniMaxAI", otherLang: "EN", switchLang: "Switch to English", dlTagline: "MiniMax 模型及其社区模型的总下载量", chart: "图表", metricModels: "模型数", metricDownloads: "下载量", chartModelsAria: (v) => `基于 MiniMax 的社区模型,目前共 ${v} 个`, chartDownloadsAria: (v) => `MiniMax 模型及其社区模型的下载量,累计 ${v}`, communityModels: "社区模型", communityDownloads: "社区下载量", minimaxModelDownloads: "MiniMax 模型下载量", minimaxDownloads: "MiniMax 下载量", builders: "开发者", openModels: () => "公开模型", moreBuilders: (n) => `另有 ${n} 位开发者`, byModality: "按模态", everyRelease: "历次发布", earlier: "更早的发布", later: "更近的发布", railCommunity: "社区模型", railDownloads: "下载量", heroCount: "个社区模型", communityDownloads30: "近 30 天社区下载量", releaseDownloads: (name) => `${name} 下载量`, growth: "增长", byTypeOverTime: "各类社区模型", newEachWeek: "每周新增", newN: "新增", weekOf: (d) => `${d}起的一周`, downloadsOverTime: "下载量走势", dailyDownloads: "每日下载量", byType: "按类型", whoBuilds: "谁在基于它开发", topModels: "近 30 天下载最多", topBuilders: "最活跃的开发者", allModels: "全部社区模型", galaxy: "星系图", type: "类型", model: "模型", modelsCol: "模型数", onHfTree: "HF 模型树", dl30Col: "近 30 天下载量", allTime: "累计下载量", days30: "近 30 天", lastDay: "最近一天", subtotal: "小计", total: "合计", modelsUnit: () => "个模型", search: "搜索模型或开发者", showMore: (n) => `再显示 ${n} 个`, rings: ["", "直接基于它", "第二代", "第三代及以后"], builtOn: "基于", downloads: "下载量", last30: "近 30 天", likes: "点赞", created: "创建于", officialTag: (name) => `${name}(官方)`, minimaxOfficial: "MiniMax 官方", galaxyCommunity: "社区模型", placing: (n) => `正在排布 ${n} 个模型…`, galaxyAria: (n, name) => `${name} 周围的 ${n} 个社区模型`, downloadPng: "下载 PNG", downloadAria: (name) => `下载 PNG:${name}`, rel: { adapter: "适配器", finetune: "微调", quantized: "量化", repackage: "格式转换", merge: "合并", mirror: "镜像", component: "组件", }, cat: { language: "语言", video: "视频", image: "图片", music: "音乐", audio: "语音" }, } const KEY = "mm-eco-lang" const valid = (s: string | null | undefined): s is Lang => s === "en" || s === "zh" function detect(): Lang { const q = new URLSearchParams(location.search).get("lang") if (valid(q)) return q try { const s = localStorage.getItem(KEY) if (valid(s)) return s } catch { /* storage blocked: fall through to the browser's language */ } return /^zh\b/i.test(navigator.languages?.[0] ?? navigator.language ?? "") ? "zh" : "en" } let lang: Lang = detect() /** The copy in the current language; reassigned by setLang. */ export let T = lang === "zh" ? zh : en const listeners = new Set<() => void>() const mark = () => (document.documentElement.lang = lang === "zh" ? "zh-CN" : "en") mark() export const getLang = () => lang export function setLang(l: Lang) { if (l === lang) return lang = l T = l === "zh" ? zh : en mark() try { localStorage.setItem(KEY, l) } catch { /* the choice lasts this visit only */ } // a shared ?lang= link would otherwise win over the choice on the next load const u = new URL(location.href) if (u.searchParams.has("lang")) { u.searchParams.set("lang", l) history.replaceState(history.state, "", u) } listeners.forEach((f) => f()) } export function useLang(): Lang { return useSyncExternalStore((f) => (listeners.add(f), () => listeners.delete(f)), getLang) } export const relName = (r: Rel) => T.rel[r] /** A modality's name: the data's English name, or its Chinese one by key. */ export const catName = (c: { key: string; name: string }) => T.cat[c.key] ?? c.name