wip(app): i18n

This commit is contained in:
Adam
2026-01-20 11:15:45 -06:00
parent 9b7d9c8173
commit f86c37f579
6 changed files with 171 additions and 12 deletions

View File

@@ -2,13 +2,25 @@
import { render } from "solid-js/web"
import { AppBaseProviders, AppInterface } from "@/app"
import { Platform, PlatformProvider } from "@/context/platform"
import { dict as en } from "@/i18n/en"
import { dict as zh } from "@/i18n/zh"
import pkg from "../package.json"
const root = document.getElementById("root")
if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
throw new Error(
"Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",
)
const locale = (() => {
if (typeof navigator !== "object") return "en" as const
const languages = navigator.languages?.length ? navigator.languages : [navigator.language]
for (const language of languages) {
if (!language) continue
if (language.toLowerCase().startsWith("zh")) return "zh" as const
}
return "en" as const
})()
const key = "error.dev.rootNotFound" as const
const message = locale === "zh" ? zh[key] ?? en[key] : en[key]
throw new Error(message)
}
const platform: Platform = {