wip(app): i18n

This commit is contained in:
Adam
2026-01-20 10:43:43 -06:00
parent be493e8be0
commit 0f2e8ea2b4
15 changed files with 110 additions and 89 deletions

View File

@@ -7,6 +7,7 @@ import { useParams } from "@solidjs/router"
import { getFilename } from "@opencode-ai/util/path"
import { useSDK } from "./sdk"
import { useSync } from "./sync"
import { useLanguage } from "@/context/language"
import { Persist, persisted } from "@/utils/persist"
export type FileSelection = {
@@ -186,6 +187,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
const sdk = useSDK()
const sync = useSync()
const params = useParams()
const language = useLanguage()
const directory = createMemo(() => sync.data.path.directory)
@@ -323,7 +325,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
)
showToast({
variant: "error",
title: "Failed to load file",
title: language.t("toast.file.loadFailed.title"),
description: e.message,
})
})

View File

@@ -41,6 +41,7 @@ import {
import { showToast } from "@opencode-ai/ui/toast"
import { getFilename } from "@opencode-ai/util/path"
import { usePlatform } from "./platform"
import { useLanguage } from "@/context/language"
import { Persist, persisted } from "@/utils/persist"
type State = {
@@ -95,6 +96,7 @@ type ChildOptions = {
function createGlobalSync() {
const globalSDK = useGlobalSDK()
const platform = usePlatform()
const language = useLanguage()
const owner = getOwner()
if (!owner) throw new Error("GlobalSync must be created within owner")
const vcsCache = new Map<string, VcsCache>()
@@ -232,7 +234,7 @@ function createGlobalSync() {
.catch((err) => {
console.error("Failed to load sessions", err)
const project = getFilename(directory)
showToast({ title: `Failed to load sessions for ${project}`, description: err.message })
showToast({ title: language.t("toast.session.listFailed.title", { project }), description: err.message })
})
sessionLoads.set(directory, promise)
@@ -658,7 +660,7 @@ function createGlobalSync() {
if (!health?.healthy) {
setGlobalStore(
"error",
new Error(`Could not connect to server. Is there a server running at \`${globalSDK.url}\`?`),
new Error(language.t("error.globalSync.connectFailed", { url: globalSDK.url })),
)
return
}

View File

@@ -10,6 +10,7 @@ import { useProviders } from "@/hooks/use-providers"
import { DateTime } from "luxon"
import { Persist, persisted } from "@/utils/persist"
import { showToast } from "@opencode-ai/ui/toast"
import { useLanguage } from "@/context/language"
export type LocalFile = FileNode &
Partial<{
@@ -42,6 +43,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
const sdk = useSDK()
const sync = useSync()
const providers = useProviders()
const language = useLanguage()
function isModelValid(model: ModelKey) {
const provider = providers.all().find((x) => x.id === model.providerID)
@@ -409,7 +411,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
.catch((e) => {
showToast({
variant: "error",
title: "Failed to load file",
title: language.t("toast.file.loadFailed.title"),
description: e.message,
})
})

View File

@@ -4,6 +4,7 @@ import { createSimpleContext } from "@opencode-ai/ui/context"
import { useGlobalSDK } from "./global-sdk"
import { useGlobalSync } from "./global-sync"
import { usePlatform } from "@/context/platform"
import { useLanguage } from "@/context/language"
import { useSettings } from "@/context/settings"
import { Binary } from "@opencode-ai/util/binary"
import { base64Encode } from "@opencode-ai/util/encode"
@@ -47,6 +48,7 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
const globalSync = useGlobalSync()
const platform = usePlatform()
const settings = useSettings()
const language = useLanguage()
const [store, setStore, _, ready] = persisted(
Persist.global("notification", ["notification.v1"]),
@@ -94,9 +96,8 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
const href = `/${base64Encode(directory)}/session/${sessionID}`
if (settings.notifications.agent()) {
void platform.notify("Response ready", session?.title ?? sessionID, href)
void platform.notify(language.t("notification.session.responseReady.title"), session?.title ?? sessionID, href)
}
break
}
case "session.error": {
@@ -115,13 +116,12 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
session: sessionID ?? "global",
error,
})
const description = session?.title ?? (typeof error === "string" ? error : "An error occurred")
const description =
session?.title ?? (typeof error === "string" ? error : language.t("notification.session.error.fallbackDescription"))
const href = sessionID ? `/${base64Encode(directory)}/session/${sessionID}` : `/${base64Encode(directory)}`
if (settings.notifications.errors()) {
void platform.notify("Session error", description, href)
void platform.notify(language.t("notification.session.error.title"), description, href)
}
break
}
}