diff --git a/.github/VOUCHED.td b/.github/VOUCHED.td index 315ff5742fd5c..2cfd35f32074d 100644 --- a/.github/VOUCHED.td +++ b/.github/VOUCHED.td @@ -52,6 +52,7 @@ github:lnieuwenhuis github:Lucenx9 github:mackinleysmith github:maria-rcks +github:maschwenk github:MatthewFeroz github:maxwellyoung github:mweinbach diff --git a/.github/workflows/mobile-fingerprint-check.yml b/.github/workflows/mobile-fingerprint-check.yml index 437f16c4684be..11d2ee60e122f 100644 --- a/.github/workflows/mobile-fingerprint-check.yml +++ b/.github/workflows/mobile-fingerprint-check.yml @@ -19,12 +19,15 @@ on: types: [opened, synchronize, reopened, edited] concurrency: - group: mobile-fingerprint-check-${{ github.event.pull_request.number }} + # A title or body edit gets its own group, so it cannot cancel the PR's real + # run and leave a cancelled check on the head commit. + group: mobile-fingerprint-check-${{ github.event.action == 'edited' && !github.event.changes.base && format('edit-{0}', github.run_id) || github.event.pull_request.number }} cancel-in-progress: true jobs: fingerprint: name: Native fingerprint diff + if: github.event.action != 'edited' || github.event.changes.base runs-on: blacksmith-8vcpu-ubuntu-2404 permissions: contents: read diff --git a/apps/desktop/gt.config.json b/apps/desktop/gt.config.json new file mode 100644 index 0000000000000..b77af550c763e --- /dev/null +++ b/apps/desktop/gt.config.json @@ -0,0 +1,10 @@ +{ + "defaultLocale": "en", + "locales": ["de", "es", "fr", "ja", "ko", "pt-BR", "ru", "sv", "zh"], + "src": ["src/**/*.ts", "!**/*.test.ts"], + "files": { + "gt": { + "output": "src/i18n/translations/[locale].json" + } + } +} diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 0daa6f14cf5c4..d91a9ee5e4cfe 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -7,7 +7,8 @@ "scripts": { "ensure:electron": "node scripts/ensure-electron-runtime.mjs", "start": "node scripts/start-electron.mjs", - "test": "vp test run --passWithNoTests" + "test": "vp test run --passWithNoTests", + "i18n:generate": "node scripts/i18n-generate.mjs" }, "dependencies": { "@clerk/electron": "catalog:", @@ -27,6 +28,7 @@ "electron-updater": "6.8.9", "electron-webauthn": "catalog:", "ffi-rs": "1.3.2", + "gt-i18n": "1.0.40", "playwright-core": "1.64.1", "react-grab": "^0.1.32", "tldts": "catalog:" @@ -37,6 +39,7 @@ "acorn": "8.16.0", "cross-env": "^10.1.0", "electron-builder": "26.16.1", + "gt": "2.27.0", "jsdom": "^30.0.1", "tailwindcss": "^4.0.0", "vite-plus": "catalog:" diff --git a/apps/desktop/scripts/i18n-generate.mjs b/apps/desktop/scripts/i18n-generate.mjs new file mode 100644 index 0000000000000..0fc5803202faa --- /dev/null +++ b/apps/desktop/scripts/i18n-generate.mjs @@ -0,0 +1,15 @@ +import * as NodeModule from "node:module"; + +// The gt CLI picks its commands from package.json, and gt-i18n alone gets no `generate`. +const { Command } = NodeModule.createRequire(import.meta.resolve("gt"))("commander"); +const { NodeCLI } = await import("gt/cli/node"); + +const program = new Command("gt"); +new NodeCLI(program, "gt-node", []).init(); +await program.parseAsync([ + "node", + "gt", + "generate", + "--skip-version-check", + ...process.argv.slice(2), +]); diff --git a/apps/desktop/src/app/DesktopApp.ts b/apps/desktop/src/app/DesktopApp.ts index 56fe979cf8c67..34476ee7855b5 100644 --- a/apps/desktop/src/app/DesktopApp.ts +++ b/apps/desktop/src/app/DesktopApp.ts @@ -42,6 +42,8 @@ import * as DesktopSnapShot from "../snapShot/DesktopSnapShot.ts"; import * as DesktopWslBackend from "../wsl/DesktopWslBackend.ts"; import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts"; import * as HostProcess from "@t3tools/shared/HostProcess"; +import { msg } from "gt-i18n"; +import { m } from "../i18n/messages.ts"; const DEFAULT_DESKTOP_BACKEND_PORT = 3773; const MAX_TCP_PORT = 65_535; @@ -147,7 +149,7 @@ const handleFatalStartupError = Effect.fn("desktop.startup.handleFatalStartupErr const wasQuitting = yield* Ref.getAndSet(state.quitting, true); if (!wasQuitting) { yield* electronDialog.showErrorBox( - "T3 Code failed to start", + m(msg("T3 Code failed to start")), `Stage: ${stage}\n${message}${detail}`, ); } @@ -216,7 +218,7 @@ const startLocalBackend = Effect.gen(function* () { owner: Option.getOrNull(owner), }); yield* (yield* ElectronDialog.ElectronDialog).showErrorBox( - "This T3 home is unavailable", + m(msg("This T3 home is unavailable")), DesktopHomeOwner.homeOwnedMessage(owner), ); yield* (yield* ElectronApp.ElectronApp).quit; diff --git a/apps/desktop/src/app/DesktopStartupRecovery.ts b/apps/desktop/src/app/DesktopStartupRecovery.ts index 769a30cf7680b..768fe2ee3d8d3 100644 --- a/apps/desktop/src/app/DesktopStartupRecovery.ts +++ b/apps/desktop/src/app/DesktopStartupRecovery.ts @@ -7,11 +7,13 @@ import type * as Scope from "effect/Scope"; import * as Stream from "effect/Stream"; import * as SubscriptionRef from "effect/SubscriptionRef"; import type * as Electron from "electron"; +import { msg } from "gt-i18n"; import * as ElectronApp from "../electron/ElectronApp.ts"; import * as ElectronShell from "../electron/ElectronShell.ts"; import * as ElectronTheme from "../electron/ElectronTheme.ts"; import * as ElectronWindow from "../electron/ElectronWindow.ts"; +import { m } from "../i18n/messages.ts"; import * as DesktopUpdates from "../updates/DesktopUpdates.ts"; import type { BackendStartupFailure } from "../backend/DesktopBackendManager.ts"; import * as DesktopEnvironment from "./DesktopEnvironment.ts"; @@ -81,30 +83,59 @@ const actionLink = (action: StartupRecoveryAction, label: string, primary = fals function describeOffer(offer: StartupRecoveryOffer): { text: string; action: string } { switch (offer._tag) { case "Checking": - return { text: "Checking for a newer version…", action: "" }; + return { text: m(msg("Checking for a newer version…")), action: "" }; case "Update": return { - text: `Version ${offer.version} is available. It can contain a fix.`, - action: actionLink("update", `Update to ${offer.version}`, true), + text: m(msg("Version {version} is available. It can contain a fix."), { + version: offer.version, + }), + action: actionLink( + "update", + m(msg("Update to {version}"), { version: offer.version }), + true, + ), }; case "Downloading": return { - text: `Downloading ${offer.version}${offer.percent === null ? "" : ` (${Math.floor(offer.percent / 10) * 10}%)`}. T3 Code restarts when the download is done.`, + text: + offer.percent === null + ? m(msg("Downloading {version}. T3 Code restarts when the download is done."), { + version: offer.version, + }) + : m( + msg( + "Downloading {version} ({percent}%). T3 Code restarts when the download is done.", + ), + { version: offer.version, percent: String(Math.floor(offer.percent / 10) * 10) }, + ), action: "", }; case "Reinstall": return { - text: `Version ${offer.version} started correctly on this computer. Download it and install it to go back.`, - action: actionLink("reinstall", `Download ${offer.version}`, true), + text: m( + msg( + "Version {version} started correctly on this computer. Download it and install it to go back.", + ), + { version: offer.version }, + ), + action: actionLink( + "reinstall", + m(msg("Download {version}"), { version: offer.version }), + true, + ), }; case "Releases": return { - text: "Get a different version from the releases page.", - action: actionLink("releases", "Open releases", true), + text: m(msg("Get a different version from the releases page.")), + action: actionLink("releases", m(msg("Open releases")), true), }; case "ManagedPolicy": return { - text: "Your organization's managed policy stopped T3 Code from starting. Send the details below to your IT administrator.", + text: m( + msg( + "Your organization's managed policy stopped T3 Code from starting. Send the details below to your IT administrator.", + ), + ), action: "", }; } @@ -118,7 +149,8 @@ function buildStartupRecoveryHtml(input: { }): string { const offer = describeOffer(input.offer); const output = input.failure.output.trim(); - return `
${escapeHtml(input.failure.reason)}
${escapeHtml(offer.text)}
-${escapeHtml(output.length > 0 ? output : "The server wrote no output.")}
-Version ${escapeHtml(input.appVersion)}. T3 Code tries again in the background. Logs: ${escapeHtml(input.logDir)}
+${escapeHtml(output.length > 0 ? output : m(msg("The server wrote no output.")))}
+${escapeHtml(m(msg("Version {version}. T3 Code tries again in the background. Logs: {logDir}"), { version: input.appVersion, logDir: input.logDir }))}
`; } @@ -270,7 +302,7 @@ export const listen: Effect.Effect< minWidth: 420, minHeight: 320, show: false, - title: "T3 Code could not start", + title: m(msg("T3 Code could not start")), autoHideMenuBar: true, backgroundColor: shouldUseDarkColors ? "#000000" : "#ffffff", webPreferences: { diff --git a/apps/desktop/src/backend/DesktopBackendPool.ts b/apps/desktop/src/backend/DesktopBackendPool.ts index 62c811996b1a0..1221b38d90204 100644 --- a/apps/desktop/src/backend/DesktopBackendPool.ts +++ b/apps/desktop/src/backend/DesktopBackendPool.ts @@ -16,6 +16,7 @@ import * as Schema from "effect/Schema"; import * as Scope from "effect/Scope"; import * as SubscriptionRef from "effect/SubscriptionRef"; import * as SynchronizedRef from "effect/SynchronizedRef"; +import { msg } from "gt-i18n"; import * as FileSystem from "effect/FileSystem"; import { HttpClient } from "effect/http"; @@ -34,6 +35,7 @@ import * as DesktopWindow from "../window/DesktopWindow.ts"; import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts"; import * as ElectronDialog from "../electron/ElectronDialog.ts"; import * as ElectronApp from "../electron/ElectronApp.ts"; +import { m } from "../i18n/messages.ts"; const { logWarning: logBackendPoolWarning } = DesktopObservability.makeComponentLogger("desktop-backend-pool"); @@ -189,8 +191,8 @@ export const layer = Layer.effect( { reason }, ); yield* electronDialog.showErrorBox( - "WSL backend is still unavailable", - `${reason}\n\nT3 Code will use the Windows backend for this launch and retry WSL the next time the app starts.`, + m(msg("WSL backend is still unavailable")), + `${reason}\n\n${m(msg("T3 Code will use the Windows backend for this launch and retry WSL the next time the app starts."))}`, ); yield* appSettings.applyWslWindowsFallbackInMemory; return true; @@ -200,8 +202,8 @@ export const layer = Layer.effect( reason, }); yield* electronDialog.showErrorBox( - "WSL backend couldn't start", - `${reason}\n\nFalling back to the Windows backend so T3 Code can open. Re-enable the WSL backend from Settings > Sharing & access once the WSL distro is fixed.`, + m(msg("WSL backend couldn't start")), + `${reason}\n\n${m(msg("Falling back to the Windows backend so T3 Code can open. Re-enable the WSL backend from Settings > Sharing & access once the WSL distro is fixed."))}`, ); // Clear wslOnly too so enabling WSL cannot restore a failed mode. // Keep the in-memory fallback if persistence fails. @@ -248,7 +250,7 @@ export const layer = Layer.effect( DesktopHomeOwner.readLiveHomeOwner().pipe( Effect.flatMap((owner) => electronDialog.showErrorBox( - "This T3 home is unavailable", + m(msg("This T3 home is unavailable")), DesktopHomeOwner.homeOwnedMessage(owner), ), ), diff --git a/apps/desktop/src/backend/DesktopHomeOwner.ts b/apps/desktop/src/backend/DesktopHomeOwner.ts index 9313591eb7b9d..7fc833a3fc104 100644 --- a/apps/desktop/src/backend/DesktopHomeOwner.ts +++ b/apps/desktop/src/backend/DesktopHomeOwner.ts @@ -7,8 +7,10 @@ import * as FileSystem from "effect/FileSystem"; import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; +import { msg } from "gt-i18n"; import * as DesktopEnvironment from "../app/DesktopEnvironment.ts"; +import { m } from "../i18n/messages.ts"; import { BACKEND_QUIT_STOP_TIMEOUT } from "./DesktopBackendManager.ts"; // The fields of the server's `server-runtime.json` that identify the owner of a T3 home. @@ -92,15 +94,44 @@ export const readLiveHomeOwner = Effect.fn("DesktopHomeOwner.readLiveHomeOwner") export const homeOwnedMessage = (owner: Option.OptionABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789 !?&@#%(){}[]
${size} pxThe quick brown fox jumps over the lazy dog.
`).join("")}`; + const escapeHtml = (text: string) => + text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); + const heading = escapeHtml(gt("Font preview")); + const sample = escapeHtml(gt("The quick brown fox jumps over the lazy dog.")); + const srcDoc = `ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789 !?&@#%(){}[]
${size} px${sample}
`).join("")}`; return ( ); diff --git a/apps/web/src/components/files/LargeTextViewer.tsx b/apps/web/src/components/files/LargeTextViewer.tsx index c95cf4e40404b..3cfe6b7fafcaa 100644 --- a/apps/web/src/components/files/LargeTextViewer.tsx +++ b/apps/web/src/components/files/LargeTextViewer.tsx @@ -1,17 +1,16 @@ +import { msg, T, useGT, useMessages } from "gt-react"; import { useEffect, useImperativeHandle, useRef, useState, type RefObject } from "react"; +import { m } from "~/i18n/messages"; import { parseDelimitedPreview } from "@t3tools/shared/delimitedPreview"; import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments"; import { useClientSettings } from "~/hooks/useSettings"; import { FileSurfaceFailure, FileSurfaceLoading, FileSurfaceNotice } from "./fileSurfaceChrome"; import { PREVIEW_PAGE_ROWS, type TextPreviewResult } from "./largeTextProtocol"; +import { previewFailureText } from "./previewFailureMessages"; import VirtualTablePreview from "./VirtualTablePreview"; const FIRST_SCREEN_BYTES = 16 * 1024; -function countLabel(count: number, noun: string) { - return `${count.toLocaleString()} ${noun}${count === 1 ? "" : "s"}`; -} - function firstScreen(text: string, delimiter: "," | "\t" | null, complete: boolean) { if (!text || text.includes("\0")) return []; const rows = delimiter @@ -43,6 +42,8 @@ export default function LargeTextViewer(props: { /** A preview's own wrap toggle; omitted follows the word wrap setting. */ readonly wordWrap?: boolean; }) { + const gt = useGT(); + const messages = useMessages(); const [meta, setMeta] = useStateThis notebook is empty.
+
+
No preview for this file
+
+
- {error} Save it or open it in another app. + {gt("{error} Save it or open it in another app.", { error })}
This sheet is empty.
+
+
No preview for this file
+
+
- {error} Save it or open it in another app. + {gt("{error} Save it or open it in another app.", { error })}
${html}
` }); + if (pages.length >= 500) throw new PreviewError({ code: "rtf-too-many-pages" }); + pages.push({ title: undefined, html: `${html}
` }); completedLength += html.length; html = ""; }; @@ -570,7 +563,7 @@ export function openRtf(bytes: ArrayBuffer): OfficeWorkerResult { encodedLength = 0; } if (completedLength + html.length + run.length > 8 * 1024 * 1024) - throw new Error("This rich text document has too much content to preview."); + throw new PreviewError({ code: "rtf-too-much-content" }); if (!run) return; let span = run; if (state.bold) span = `${span}`; @@ -587,7 +580,7 @@ export function openRtf(bytes: ArrayBuffer): OfficeWorkerResult { if (state.skip) return; run += escape(value); if (completedLength + html.length + run.length > 8 * 1024 * 1024) - throw new Error("This rich text document has too much content to preview."); + throw new PreviewError({ code: "rtf-too-much-content" }); }; const emitByte = (value: number) => { if (fallback > 0) fallback--; @@ -598,19 +591,19 @@ export function openRtf(bytes: ArrayBuffer): OfficeWorkerResult { if (char === "{") { flush(); fallback = 0; - if (stack.length > 100) throw new Error("This rich text document is nested too deeply."); + if (stack.length > 100) throw new PreviewError({ code: "rtf-too-deep" }); stack.push({ ...state }); } else if (char === "}") { flush(); fallback = 0; const parent = stack.pop(); - if (!parent) throw new Error("This rich text document is damaged."); + if (!parent) throw new PreviewError({ code: "rtf-damaged" }); state = parent; } else if (char === "\\") { const next = source[i]; if (next === "'") { const hex = source.slice(i + 1, i + 3); - if (!/^[\da-f]{2}$/i.test(hex)) throw new Error("Invalid rich text byte escape."); + if (!/^[\da-f]{2}$/i.test(hex)) throw new PreviewError({ code: "rtf-byte-escape" }); i += 3; emitByte(Number.parseInt(hex, 16)); continue; @@ -690,7 +683,7 @@ export function openRtf(bytes: ArrayBuffer): OfficeWorkerResult { state.skip = true; else if (word === "bin") { if (!Number.isSafeInteger(arg) || arg < 0 || arg > source.length - i) - throw new Error("Invalid rich text binary data."); + throw new PreviewError({ code: "rtf-binary-data" }); i += arg; } else if (word === "ansicpg") { const label = @@ -707,7 +700,7 @@ export function openRtf(bytes: ArrayBuffer): OfficeWorkerResult { try { state.decoder = new TextDecoder(label); } catch { - throw new Error("This rich text code page is not supported."); + throw new PreviewError({ code: "rtf-code-page" }); } } else if (word === "b") state.bold = arg !== 0; else if (word === "i") state.italic = arg !== 0; @@ -728,7 +721,7 @@ export function openRtf(bytes: ArrayBuffer): OfficeWorkerResult { } } else if (char !== "\r" && char !== "\n" && char) emitByte(char.charCodeAt(0)); } - if (stack.length) throw new Error("This rich text document is damaged."); + if (stack.length) throw new PreviewError({ code: "rtf-damaged" }); flush(); if (html || !pages.length) finishPage(); return { type: "document", navigation: "page", pages }; diff --git a/apps/web/src/components/files/fileCommentAnnotations.ts b/apps/web/src/components/files/fileCommentAnnotations.ts index 2ee2ccb0c0f8b..e78e753b6ab54 100644 --- a/apps/web/src/components/files/fileCommentAnnotations.ts +++ b/apps/web/src/components/files/fileCommentAnnotations.ts @@ -1,4 +1,6 @@ import type { LineAnnotation, SelectedLineRange } from "@pierre/diffs"; +import { msg } from "gt-react"; +import { m, type MessageResolver } from "~/i18n/messages"; export interface FileCommentAnnotationEntry { id: string; @@ -31,8 +33,14 @@ export function normalizeFileCommentRange(range: SelectedLineRange): { }; } -export function formatFileCommentRange(startLine: number, endLine: number): string { - return startLine === endLine ? `L${startLine}` : `L${startLine} to L${endLine}`; +export function formatFileCommentRange( + startLine: number, + endLine: number, + resolve: MessageResolver = m, +): string { + return startLine === endLine + ? `L${startLine}` + : resolve(msg("L{start} to L{end}", { start: String(startLine), end: String(endLine) })); } export function remapFileCommentAnnotations( diff --git a/apps/web/src/components/files/filePreviewMode.ts b/apps/web/src/components/files/filePreviewMode.ts index 4fca2af1c183b..f18f6dd69a09b 100644 --- a/apps/web/src/components/files/filePreviewMode.ts +++ b/apps/web/src/components/files/filePreviewMode.ts @@ -1,6 +1,9 @@ import type { AssetResource, ProjectReadFileError, ScopedThreadRef } from "@t3tools/contracts"; import { mediaFileReference } from "@t3tools/client-runtime/media-reference"; import { isHostPath, workspaceRelativeFilePath } from "@t3tools/shared/path"; +import { msg } from "gt-react"; + +import { m, type MessageResolver } from "~/i18n/messages"; export function resolveFilePreviewPath(path: string | null, cwd: string): string | null { if (path === null) return null; @@ -10,20 +13,25 @@ export function resolveFilePreviewPath(path: string | null, cwd: string): string export const isMarkdownPreviewFile = (path: string): boolean => /\.(?:md|mdx|markdown|mdown|mkd)$/i.test(path); -export function filePreviewReadErrorMessage(error: ProjectReadFileError): string { +export function filePreviewReadErrorMessage( + error: ProjectReadFileError, + resolve: MessageResolver = m, +): string { switch (error.failure) { case "path_not_file": - return "The path is a directory or special file, not a regular file."; + return resolve(msg("The path is a directory or special file, not a regular file.")); case "binary_file": - return "The file is binary and cannot be displayed as text."; + return resolve(msg("The file is binary and cannot be displayed as text.")); case "workspace_path_outside_root": - return "The requested path is outside the workspace."; + return resolve(msg("The requested path is outside the workspace.")); case "resolved_path_outside_root": - return "The path resolves to a location outside the workspace."; + return resolve(msg("The path resolves to a location outside the workspace.")); case "operation_failed": return error.operation === "realpath-workspace-root" - ? "The workspace folder could not be accessed." - : "The file could not be accessed or read. It may be missing or inaccessible."; + ? resolve(msg("The workspace folder could not be accessed.")) + : resolve( + msg("The file could not be accessed or read. It may be missing or inaccessible."), + ); default: return error.message; } diff --git a/apps/web/src/components/files/fileSurfaceChrome.tsx b/apps/web/src/components/files/fileSurfaceChrome.tsx index df0de1ed81d1e..4104e87a1c70e 100644 --- a/apps/web/src/components/files/fileSurfaceChrome.tsx +++ b/apps/web/src/components/files/fileSurfaceChrome.tsx @@ -1,5 +1,6 @@ import type { ReactNode } from "react"; +import { T, useGT } from "gt-react"; import { Spinner } from "~/components/ui/spinner"; import { Button } from "~/components/ui/button"; import { Toggle } from "~/components/ui/toggle"; @@ -114,10 +115,11 @@ export function FileSurfaceNotice(props: { readonly children: ReactNode }) { } export function FileSurfaceLoading(props: { readonly className?: string }) { + const gt = useGT(); return (Hidden slide
: null} + {slide.hidden ? ( +
+
{slide.notes}
diff --git a/apps/web/src/components/files/office/Spreadsheet.tsx b/apps/web/src/components/files/office/Spreadsheet.tsx
index eaae7533b7b5b..2b09e417dea5d 100644
--- a/apps/web/src/components/files/office/Spreadsheet.tsx
+++ b/apps/web/src/components/files/office/Spreadsheet.tsx
@@ -1,6 +1,8 @@
import * as Schema from "effect/Schema";
import { observeResize } from "~/lib/observeResize";
+import { msg, useGT } from "gt-react";
import { useEffect, useRef, useState } from "react";
+import { m } from "~/i18n/messages";
import {
cellAtPoint,
normalizeRange,
@@ -52,6 +54,7 @@ export default function Spreadsheet(props: {
onError: (cause: unknown) => void;
}) {
const { onError, bytes: source, onDetails, view } = props;
+ const gt = useGT();
const [opened, setOpened] = useState {STATUS_LABEL[message.status]} {m(STATUS_LABEL[message.status])}
+
{files.map((staged) => (
{staged.file.name}
- {formatAttachmentSize(staged.file.size)}
+ {formatAttachmentSize(staged.file.size, m)}
)}
) : null}
- The owner approves each message
+
Nothing has happened here yet.
+
+