fix: update i18n - text verdicts from analyze tools

This commit is contained in:
2026-09-13 06:38:58 +05:00
parent 4b44bc439c
commit 372babc3b7
5 changed files with 30 additions and 20 deletions
@@ -10,6 +10,7 @@
interface Props { interface Props {
inputMode: InputMode; inputMode: InputMode;
resultKind?: ResultKind; resultKind?: ResultKind;
toolId: string;
source: PixelImage | null; source: PixelImage | null;
result: PixelImage | null; result: PixelImage | null;
fileResult?: FileResult | null; fileResult?: FileResult | null;
@@ -27,6 +28,7 @@
let { let {
inputMode, inputMode,
resultKind = "image", resultKind = "image",
toolId,
source, source,
result, result,
fileResult = null, fileResult = null,
@@ -104,6 +106,7 @@
{result} {result}
{fileResult} {fileResult}
{textResult} {textResult}
{toolId}
{running} {running}
oncopy={oncopytext} oncopy={oncopytext}
{ondownloadtxt} {ondownloadtxt}
@@ -12,6 +12,7 @@
result: PixelImage | null; result: PixelImage | null;
fileResult?: FileResult | null; fileResult?: FileResult | null;
textResult?: string | null; textResult?: string | null;
toolId?: string;
running?: boolean; running?: boolean;
oncopy?: () => void; oncopy?: () => void;
ondownloadtxt?: () => void; ondownloadtxt?: () => void;
@@ -21,6 +22,7 @@
result, result,
fileResult = null, fileResult = null,
textResult = null, textResult = null,
toolId = "",
running = false, running = false,
oncopy, oncopy,
ondownloadtxt, ondownloadtxt,
@@ -62,6 +64,7 @@
<SchemaTextResult <SchemaTextResult
value={textResult} value={textResult}
kind="verdict" kind="verdict"
{toolId}
oncopy={oncopy ?? (() => {})} oncopy={oncopy ?? (() => {})}
ondownload={ondownloadtxt ?? (() => {})} ondownload={ondownloadtxt ?? (() => {})}
/> />
@@ -1,11 +1,13 @@
<script lang="ts"> <script lang="ts">
import { Copy, Download, FileText } from "@lucide/svelte"; import { Copy, Download, FileText } from "@lucide/svelte";
import { verdictTone, verdictText } from "$lib/i18n/schema-tool-strings";
import { t } from "$lib/i18n/t"; import { t } from "$lib/i18n/t";
import IconButton from "./ui/IconButton.svelte"; import IconButton from "./ui/IconButton.svelte";
interface Props { interface Props {
value: string; value: string;
kind: "text" | "verdict"; kind: "text" | "verdict";
toolId?: string;
fileName?: string; fileName?: string;
oncopy: () => void; oncopy: () => void;
ondownload: () => void; ondownload: () => void;
@@ -13,17 +15,15 @@
let { let {
value, value,
kind, kind,
toolId = "",
fileName = "result.txt", fileName = "result.txt",
oncopy, oncopy,
ondownload, ondownload,
}: Props = $props(); }: Props = $props();
const tone = $derived( const tone = $derived(verdictTone(value));
/^(yes|true)/i.test(value.trim()) const displayValue = $derived(
? "success" kind === "verdict" && toolId ? verdictText(toolId, value) : value,
: /^(no|false)/i.test(value.trim())
? "danger"
: "info",
); );
</script> </script>
@@ -31,7 +31,7 @@
<div class="verdict"> <div class="verdict">
<span class="verdict-label">{t("resultCard.result")}</span> <span class="verdict-label">{t("resultCard.result")}</span>
<div class="badge badge-tone--{tone}" role="status"> <div class="badge badge-tone--{tone}" role="status">
<span class="verdict-text">{value}</span> <span class="verdict-text">{displayValue}</span>
<IconButton icon={Copy} label={t("textResult.copy")} onclick={oncopy} /> <IconButton icon={Copy} label={t("textResult.copy")} onclick={oncopy} />
</div> </div>
</div> </div>
+9 -2
View File
@@ -6,7 +6,11 @@
import { decodeFile, encode } from "$lib/core/io"; import { decodeFile, encode } from "$lib/core/io";
import type { PixelImage } from "$lib/core/types"; import type { PixelImage } from "$lib/core/types";
import { execute } from "$lib/executor"; import { execute } from "$lib/executor";
import { toolDescription, toolTitle } from "$lib/i18n/schema-tool-strings"; import {
toolDescription,
toolTitle,
verdictText,
} from "$lib/i18n/schema-tool-strings";
import { t } from "$lib/i18n/t"; import { t } from "$lib/i18n/t";
import type { FileResult, ToolEntry } from "$lib/registry"; import type { FileResult, ToolEntry } from "$lib/registry";
import { import {
@@ -120,8 +124,10 @@
async function copyText() { async function copyText() {
if (!textResult) return; if (!textResult) return;
const copyValue =
resultKind === "verdict" ? verdictText(tool.id, textResult) : textResult;
try { try {
await navigator.clipboard.writeText(textResult); await navigator.clipboard.writeText(copyValue);
} catch (e) { } catch (e) {
error = errorText(e); error = errorText(e);
} }
@@ -178,6 +184,7 @@
<section class="panel"> <section class="panel">
<SchemaPreview <SchemaPreview
toolId={tool.id}
{source} {source}
{result} {result}
{fileResult} {fileResult}
+8 -11
View File
@@ -10,6 +10,7 @@ import {
import { hasTransparency, isGrayscale, orientationOf } from "../core/analyze"; import { hasTransparency, isGrayscale, orientationOf } from "../core/analyze";
import { encode } from "../core/io"; import { encode } from "../core/io";
import { base64ToBytes, looksLikePng, stripDataUri } from "../core/textio"; import { base64ToBytes, looksLikePng, stripDataUri } from "../core/textio";
import { t } from "../i18n/t";
interface ExtractColorParams { interface ExtractColorParams {
color: string; color: string;
@@ -204,9 +205,7 @@ const verifyIsPng: ToolEntry<NoParams> = {
input: "text", input: "text",
result: "verdict", result: "verdict",
run: textGen((text) => run: textGen((text) =>
looksLikePng(base64ToBytes(stripDataUri(text))) looksLikePng(base64ToBytes(stripDataUri(text))) ? "verifyYes" : "verifyNo",
? "Yes — valid PNG signature."
: "No — the content is not a PNG.",
), ),
}; };
@@ -218,9 +217,7 @@ const pngIsGrayscale: ToolEntry<NoParams> = {
schema: emptySchema, schema: emptySchema,
input: "image", input: "image",
result: "verdict", result: "verdict",
run: imgTool((img) => run: imgTool((img) => (isGrayscale(img) ? "grayscaleYes" : "grayscaleNo")),
isGrayscale(img) ? "Yes — grayscale." : "No — contains colors.",
),
}; };
const pngFileSize: ToolEntry<NoParams> = { const pngFileSize: ToolEntry<NoParams> = {
@@ -236,7 +233,7 @@ const pngFileSize: ToolEntry<NoParams> = {
const blob = await encode(img, "image/png"); const blob = await encode(img, "image/png");
const kb = blob.size / 1024; const kb = blob.size / 1024;
const kbText = kb >= 100 ? Math.round(kb).toString() : kb.toFixed(1); const kbText = kb >= 100 ? Math.round(kb).toString() : kb.toFixed(1);
return `${kbText} KB`; return t("tools.png-file-size.results.line", { kb: kbText });
}), }),
}; };
@@ -250,7 +247,7 @@ const pngIsTransparent: ToolEntry<NoParams> = {
input: "image", input: "image",
result: "verdict", result: "verdict",
run: imgTool((img) => run: imgTool((img) =>
hasTransparency(img) ? "Yes — has transparency." : "No — fully opaque.", hasTransparency(img) ? "transparentYes" : "transparentNo",
), ),
}; };
@@ -265,11 +262,11 @@ const pngOrientation: ToolEntry<NoParams> = {
run: imgTool((img) => { run: imgTool((img) => {
switch (orientationOf(img)) { switch (orientationOf(img)) {
case "portrait": case "portrait":
return "Portrait"; return "orientationPortrait";
case "landscape": case "landscape":
return "Landscape"; return "orientationLandscape";
default: default:
return "Square"; return "orientationSquare";
} }
}), }),
}; };