diff options
| author | Adam <[email protected]> | 2026-02-27 09:45:00 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-27 09:45:00 -0600 |
| commit | 6ef3af73dfa1c72bb2001c86d898f2edf8ea4b10 (patch) | |
| tree | 845adb9ccc47884a0f102a59cb887bd17a51a75c /packages/app/src/utils | |
| parent | e5ae6c51b0d2f5dececd16970250aa2ab6c71a2f (diff) | |
| download | opencode-6ef3af73dfa1c72bb2001c86d898f2edf8ea4b10.tar.gz opencode-6ef3af73dfa1c72bb2001c86d898f2edf8ea4b10.zip | |
chore(app): i18n sync (#15362)
Diffstat (limited to 'packages/app/src/utils')
| -rw-r--r-- | packages/app/src/utils/server-errors.ts | 27 | ||||
| -rw-r--r-- | packages/app/src/utils/time.ts | 18 |
2 files changed, 35 insertions, 10 deletions
diff --git a/packages/app/src/utils/server-errors.ts b/packages/app/src/utils/server-errors.ts index 4b9727e61..85ebca132 100644 --- a/packages/app/src/utils/server-errors.ts +++ b/packages/app/src/utils/server-errors.ts @@ -7,11 +7,28 @@ export type ConfigInvalidError = { } } -export function formatServerError(error: unknown) { - if (isConfigInvalidErrorLike(error)) return parseReabaleConfigInvalidError(error) +type Label = { + unknown: string + invalidConfiguration: string +} + +const fallback: Label = { + unknown: "Unknown error", + invalidConfiguration: "Invalid configuration", +} + +function resolveLabel(labels: Partial<Label> | undefined): Label { + return { + unknown: labels?.unknown ?? fallback.unknown, + invalidConfiguration: labels?.invalidConfiguration ?? fallback.invalidConfiguration, + } +} + +export function formatServerError(error: unknown, labels?: Partial<Label>) { + if (isConfigInvalidErrorLike(error)) return parseReabaleConfigInvalidError(error, labels) if (error instanceof Error && error.message) return error.message if (typeof error === "string" && error) return error - return "Unknown error" + return resolveLabel(labels).unknown } function isConfigInvalidErrorLike(error: unknown): error is ConfigInvalidError { @@ -20,8 +37,8 @@ function isConfigInvalidErrorLike(error: unknown): error is ConfigInvalidError { return o.name === "ConfigInvalidError" && typeof o.data === "object" && o.data !== null } -export function parseReabaleConfigInvalidError(errorInput: ConfigInvalidError) { - const head = "Invalid configuration" +export function parseReabaleConfigInvalidError(errorInput: ConfigInvalidError, labels?: Partial<Label>) { + const head = resolveLabel(labels).invalidConfiguration const file = errorInput.data.path && errorInput.data.path !== "config" ? errorInput.data.path : "" const detail = errorInput.data.message?.trim() ?? "" const issues = (errorInput.data.issues ?? []).map((issue) => { diff --git a/packages/app/src/utils/time.ts b/packages/app/src/utils/time.ts index ac709d86d..d183e1080 100644 --- a/packages/app/src/utils/time.ts +++ b/packages/app/src/utils/time.ts @@ -1,4 +1,12 @@ -export function getRelativeTime(dateString: string): string { +type TimeKey = + | "common.time.justNow" + | "common.time.minutesAgo.short" + | "common.time.hoursAgo.short" + | "common.time.daysAgo.short" + +type Translate = (key: TimeKey, params?: Record<string, string | number>) => string + +export function getRelativeTime(dateString: string, t: Translate): string { const date = new Date(dateString) const now = new Date() const diffMs = now.getTime() - date.getTime() @@ -7,8 +15,8 @@ export function getRelativeTime(dateString: string): string { const diffHours = Math.floor(diffMinutes / 60) const diffDays = Math.floor(diffHours / 24) - if (diffSeconds < 60) return "Just now" - if (diffMinutes < 60) return `${diffMinutes}m ago` - if (diffHours < 24) return `${diffHours}h ago` - return `${diffDays}d ago` + if (diffSeconds < 60) return t("common.time.justNow") + if (diffMinutes < 60) return t("common.time.minutesAgo.short", { count: diffMinutes }) + if (diffHours < 24) return t("common.time.hoursAgo.short", { count: diffHours }) + return t("common.time.daysAgo.short", { count: diffDays }) } |
