feat(app): initial i18n stubbing

This commit is contained in:
Adam
2026-01-19 15:50:23 -06:00
parent 7f50b27996
commit 0470717c7f
7 changed files with 151 additions and 9 deletions

View File

@@ -69,6 +69,7 @@ import { DialogSelectDirectory } from "@/components/dialog-select-directory"
import { DialogEditProject } from "@/components/dialog-edit-project"
import { Titlebar } from "@/components/titlebar"
import { useServer } from "@/context/server"
import { useLanguage, type Locale } from "@/context/language"
export default function Layout(props: ParentProps) {
const [store, setStore, , ready] = persisted(
@@ -109,6 +110,7 @@ export default function Layout(props: ParentProps) {
const dialog = useDialog()
const command = useCommand()
const theme = useTheme()
const language = useLanguage()
const initialDir = params.dir
const availableThemeEntries = createMemo(() => Object.entries(theme.themes()))
const colorSchemeOrder: ColorScheme[] = ["system", "light", "dark"]
@@ -268,6 +270,24 @@ export default function Layout(props: ParentProps) {
})
}
function setLocale(next: Locale) {
if (next === language.locale()) return
language.setLocale(next)
showToast({
title: language.t("toast.language.title"),
description: language.t("toast.language.description", { language: language.label(next) }),
})
}
function cycleLanguage(direction = 1) {
const locales = language.locales
const currentIndex = locales.indexOf(language.locale())
const nextIndex = currentIndex === -1 ? 0 : (currentIndex + direction + locales.length) % locales.length
const next = locales[nextIndex]
if (!next) return
setLocale(next)
}
onMount(() => {
if (!platform.checkUpdate || !platform.update || !platform.restart) return
@@ -906,6 +926,22 @@ export default function Layout(props: ParentProps) {
})
}
commands.push({
id: "language.cycle",
title: language.t("command.language.cycle"),
category: language.t("command.category.language"),
onSelect: () => cycleLanguage(1),
})
for (const locale of language.locales) {
commands.push({
id: `language.set.${locale}`,
title: language.t("command.language.set", { language: language.label(locale) }),
category: language.t("command.category.language"),
onSelect: () => setLocale(locale),
})
}
return commands
})