From 71b5c90a4a66ac3ce631c0c0cc038cfbb29224d1 Mon Sep 17 00:00:00 2001 From: Ku6epXBOCTuK Date: Sat, 12 Sep 2026 21:48:39 +0500 Subject: [PATCH] docs: add audit tools --- web/src/lib/components/SchemaFields.svelte | 1 + web/src/lib/i18n/schema-tool-strings.ts | 65 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 web/src/lib/i18n/schema-tool-strings.ts diff --git a/web/src/lib/components/SchemaFields.svelte b/web/src/lib/components/SchemaFields.svelte index 1fee64b..f2d1363 100644 --- a/web/src/lib/components/SchemaFields.svelte +++ b/web/src/lib/components/SchemaFields.svelte @@ -4,6 +4,7 @@ FieldSpecKind, ToolSchema, } from "$lib/registry-schema"; + import { fieldLabel as labelOf } from "$lib/i18n/schema-tool-strings"; import { RotateCcw } from "@lucide/svelte"; import type { Component } from "svelte"; import DimensionField from "./fields/DimensionField.svelte"; diff --git a/web/src/lib/i18n/schema-tool-strings.ts b/web/src/lib/i18n/schema-tool-strings.ts new file mode 100644 index 0000000..993e547 --- /dev/null +++ b/web/src/lib/i18n/schema-tool-strings.ts @@ -0,0 +1,65 @@ +import type { ToolEntry } from "$lib/registry"; +import type { Field } from "$lib/registry-schema"; +import { ru } from "./ru"; +import { getMergedDict } from "./locale.svelte"; +import type { SearchDoc } from "./matching"; +import { t } from "./t"; + +function labelOf(id: string): string { + return id + .replace(/([a-z])([A-Z])/g, "$1 $2") + .replace(/[_-]+/g, " ") + .replace(/\b\w/g, (c) => c.toUpperCase()); +} + +export function toolTitle(tool: ToolEntry): string { + return getMergedDict().tools[tool.id]?.title ?? tool.title; +} + +export function toolDescription(tool: ToolEntry): string { + return getMergedDict().tools[tool.id]?.description ?? tool.description; +} + +export function fieldLabel(field: Field, id: string): string { + const key = (field.spec as { label?: string }).label; + if (key) { + const translated = t(key); + if (translated !== key) return translated; + } + return labelOf(id); +} + +export function groupLabel(title: string): string { + return t(title); +} + +export function verdictText(toolId: string, key: string): string { + return getMergedDict().tools[toolId]?.results?.[key] ?? key; +} + +export function verdictTone(key: string): "success" | "danger" | "info" { + if (/[Yy]es$|[Tt]rue$/.test(key)) return "success"; + if (/[Nn]o$|[Ff]alse$/.test(key)) return "danger"; + return "info"; +} + +function dedupe(values: string[]): string[] { + return [...new Set(values.filter((v) => v.length > 0))]; +} + +export function toolSearchDoc(tool: ToolEntry): SearchDoc { + const active = getMergedDict().tools[tool.id]; + return { + id: tool.id, + titles: dedupe([ + active?.title ?? "", + ru.tools[tool.id]?.title ?? "", + tool.title, + ]), + descriptions: dedupe([ + active?.description ?? "", + ru.tools[tool.id]?.description ?? "", + tool.description, + ]), + }; +}