Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

contractLabels.ts

310 lines10.8 KB

1/**
2 * Translatable copies of the English labels in `@t3tools/contracts` helpers. Same ids, same
3 * English; apps call these instead of the contracts helpers so the text follows the UI language.
4 */
5import {
6 type BrowserImportFailureReason,
7 isRuntimeModeAbove,
8 managedCapabilityDenial as contractsManagedCapabilityDenial,
9 managedUpdatesDenial as contractsManagedUpdatesDenial,
10 type ManagedPolicySummary,
11 type ProjectCloneSnapshot,
12 type ProjectCloneStage,
13 type RuntimeMode,
14 type WorktreeSetupStageId,
15 worktreeSetupStageLabel as contractsWorktreeSetupStageLabel,
16} from "@t3tools/contracts";
17import type { IdleCompactionMode } from "@t3tools/contracts/settings";
18import { mFallback, msg } from "gt-i18n";
19import type { MFunctionType } from "gt-i18n/types";
20​
21// Contracts decides each stage's English label; this table only makes that text translatable.
22const WORKTREE_SETUP_STAGE_LABELS: Readonly<Record<string, string>> = {
23 "Fetch base branch": msg("Fetch base branch"),
24 "Check out files": msg("Check out files"),
25 "Init submodules": msg("Init submodules"),
26 "Run setup script": msg("Run setup script"),
27 "Start agent": msg("Start agent"),
28};
29​
30/** @public */
31export function worktreeSetupStageLabel(
32 id: WorktreeSetupStageId,
33 resolve: MFunctionType = mFallback,
34): string {
35 const english = contractsWorktreeSetupStageLabel(id);
36 return resolve(WORKTREE_SETUP_STAGE_LABELS[english] ?? english);
38​
39const PROJECT_CLONE_STAGE_LABELS: Record<ProjectCloneStage, string> = {
40 connecting: msg("Connecting", { $context: "git clone stage" }),
41 counting: msg("Counting objects"),
42 receiving: msg("Receiving objects"),
43 resolving: msg("Resolving deltas"),
44 checkout: msg("Checking out files"),
45};
46​
47/** @public */
48export function projectCloneStageLabel(
49 stage: ProjectCloneStage,
50 resolve: MFunctionType = mFallback,
51): string {
52 return resolve(PROJECT_CLONE_STAGE_LABELS[stage]);
54​
55/** @public */
56export function projectCloneProgressSummary(
57 snapshot: Pick<ProjectCloneSnapshot, "stage" | "percent" | "detail" | "stalled">,
58 resolve: MFunctionType = mFallback,
59): string {
60 const parts = [projectCloneStageLabel(snapshot.stage, resolve)];
61 if (snapshot.percent !== null) parts.push(`${snapshot.percent}%`);
62 // The detail carries git's last transfer speed, which a stall makes a lie.
63 if (snapshot.stalled) parts.push(resolve(msg("Stalled", { $context: "git clone progress" })));
64 else if (snapshot.detail) parts.push(snapshot.detail);
65 return parts.join(" · ");
67​
68/** @public */
69export function managedUpdatesMessage(
70 organization: string,
71 resolve: MFunctionType = mFallback,
72): string {
73 return resolve(msg("{organization} manages T3 Code updates.", { organization }));
75​
76/** @public */
77export function managedNightlyDeniedMessage(
78 organization: string,
79 resolve: MFunctionType = mFallback,
80): string {
81 return resolve(
82 msg("{organization} manages T3 Code updates. Only stable releases can be installed.", {
83 organization,
84 }),
85 );
87​
88/** @public */
89export function managedUpdatesDenial(
90 summary: ManagedPolicySummary | undefined,
91 resolve: MFunctionType = mFallback,
92): string | undefined {
93 return summary !== undefined && contractsManagedUpdatesDenial(summary) !== undefined
94 ? managedUpdatesMessage(summary.organization, resolve)
95 : undefined;
97​
98/** @public */
99export function managedRuntimeModeCeilingMessage(
100 organization: string,
101 ceiling: RuntimeMode,
102 resolve: MFunctionType = mFallback,
103): string {
104 switch (ceiling) {
105 case "approval-required":
106 return resolve(msg("{organization} limits threads to Supervised.", { organization }));
107 case "auto-accept-edits":
108 return resolve(msg("{organization} limits threads to Auto-accept edits.", { organization }));
109 case "auto":
110 return resolve(msg("{organization} limits threads to Auto.", { organization }));
111 case "full-access":
112 return resolve(msg("{organization} limits threads to Full access.", { organization }));
113 }
115​
116/** @public */
117export function managedRuntimeModeDenial(
118 summary: ManagedPolicySummary | undefined,
119 mode: RuntimeMode,
120 resolve: MFunctionType = mFallback,
121): string | undefined {
122 const ceiling = summary?.limits?.maxRuntimeMode;
123 return summary !== undefined && ceiling !== undefined && isRuntimeModeAbove(mode, ceiling)
124 ? managedRuntimeModeCeilingMessage(summary.organization, ceiling, resolve)
125 : undefined;
127​
128export type ManagedCapability =
129 | "remoteClients"
130 | "connect"
131 | "webhookTasks"
132 | "browserCookieImport"
133 | "previewTunnel"
134 | "worktreeLayoutCommands";
135​
136function managedCapabilityDeniedMessage(
137 organization: string,
138 capability: ManagedCapability,
139 resolve: MFunctionType,
140): string {
141 switch (capability) {
142 case "remoteClients":
143 return resolve(
144 msg("{organization}'s policy does not allow connecting from other devices.", {
145 organization,
146 }),
147 );
148 case "connect":
149 return resolve(msg("{organization}'s policy does not allow T3 Connect.", { organization }));
150 case "webhookTasks":
151 return resolve(
152 msg("{organization}'s policy does not allow webhook tasks.", { organization }),
153 );
154 case "browserCookieImport":
155 return resolve(
156 msg("{organization}'s policy does not allow importing browser cookies.", {
157 organization,
158 }),
159 );
160 case "previewTunnel":
161 return resolve(
162 msg(
163 "{organization}'s policy does not allow opening this machine's local servers on other devices.",
164 { organization },
165 ),
166 );
167 case "worktreeLayoutCommands":
168 return resolve(
169 msg("{organization}'s policy does not allow project worktree layout commands.", {
170 organization,
171 }),
172 );
173 }
175​
176/** @public */
177export function managedCapabilityDenial(
178 summary: ManagedPolicySummary | undefined,
179 capability: ManagedCapability,
180 resolve: MFunctionType = mFallback,
181): string | undefined {
182 return summary !== undefined &&
183 contractsManagedCapabilityDenial(summary, capability) !== undefined
184 ? managedCapabilityDeniedMessage(summary.organization, capability, resolve)
185 : undefined;
187​
188const IDLE_COMPACTION_MODE_LABELS: Record<IdleCompactionMode | "default", string> = {
189 default: msg("Use default"),
190 onReturn: msg("When you return"),
191 beforeCacheExpires: msg("Before the cache expires (beta)"),
192 off: msg("Never", { $context: "idle compaction mode" }),
193};
194​
195/** @public Labels for `IDLE_COMPACTION_MODES` values, plus the per-instance "default". */
196export function idleCompactionModeLabel(
197 mode: IdleCompactionMode | "default",
198 resolve: MFunctionType = mFallback,
199): string {
200 return resolve(IDLE_COMPACTION_MODE_LABELS[mode]);
202​
203const BROWSER_IMPORT_FAILURE_MESSAGES: Record<BrowserImportFailureReason, string> = {
204 notInstalled: msg("Not installed on this machine."),
205 needsKeychainApproval: msg("Needs Keychain access to read its cookies."),
206 keychainItemMissing: msg(
207 "No encryption key in your Keychain. Sign in to that browser once, then retry.",
208 ),
209 needsFullDiskAccess: msg(
210 "Give T3 Code Full Disk Access in System Settings → Privacy & Security, then retry.",
211 ),
212 browserRunning: msg("Quit the browser first so its cookie database can be read."),
213 unsupportedPlatform: msg("Importing from this browser isn't possible on this platform."),
214 keychainUnavailable: msg(
215 "The system keyring could not be accessed. Make sure your desktop keyring is running and unlocked, then retry.",
216 ),
217 unknownSource: msg("That browser is no longer available to import from."),
218 unknownSourceProfile: msg("That browser profile no longer exists."),
219 sessionUnavailable: msg("The target profile could not be opened."),
220 profileNotSaved: msg(
221 "The cookies were imported, but the new profile couldn't be saved. Try again.",
222 ),
223 profileLimitReached: msg(
224 "You've reached the profile limit. Delete a profile or import into an existing one.",
225 ),
226 readFailed: msg("The browser's cookie database could not be read."),
227};
228​
229/** @public `BROWSER_IMPORT_FAILURE_COPY[reason]`, translated. */
230export function browserImportFailureMessage(
231 reason: BrowserImportFailureReason,
232 resolve: MFunctionType = mFallback,
233): string {
234 return resolve(BROWSER_IMPORT_FAILURE_MESSAGES[reason]);
236​
237// The server's source-control discovery hints, in the same English; commands and URLs stay as is.
238const INSTALL_HINTS = [
239 msg("Install Git from {url} or with your package manager.", {
240 url: "https://git-scm.com/downloads",
241 }),
242 msg("Install Jujutsu with {command} or from {url}.", {
243 command: "`brew install jj`",
244 url: "https://github.com/jj-vcs/jj",
245 }),
246 msg(
247 "Install the GitHub command-line tool ({cli}) via {url} or your package manager (for example {command}).",
248 {
249 cli: "`gh`",
250 url: "https://cli.github.com/",
251 command: "`brew install gh`",
252 },
253 ),
254 msg(
255 "Install the GitLab command-line tool ({cli}) from {url} or your package manager (for example {command}).",
256 {
257 cli: "`glab`",
258 url: "https://gitlab.com/gitlab-org/cli",
259 command: "`brew install glab`",
260 },
261 ),
262 msg(
263 "Install the Azure command-line tools ({cli}), then enable Azure DevOps support with {command}.",
264 {
265 cli: "`az`",
266 command: "`az extension add --name azure-devops`",
267 },
268 ),
269 msg("Add a Bitbucket token in Settings → Source control & issues."),
270 msg("Install the Origin CLI with {install}, then run {login}.", {
271 install: "`curl -fsSL https://downloads.cursor.com/origin/install.sh | sh`",
272 login: "`origin auth login`",
273 }),
274 msg(
275 "Install {fj} 0.6 or later from {fjUrl} and run {fjLogin}, or install {tea} 0.16 or later from {teaUrl} and run {teaLogin} for each Forgejo or Gitea server.",
276 {
277 fj: "`fj`",
278 fjUrl: "https://codeberg.org/forgejo-contrib/forgejo-cli",
279 fjLogin: "`fj --host <server-url> auth add-token`",
280 tea: "`tea`",
281 teaUrl: "https://gitea.com/gitea/tea",
282 teaLogin: "`tea login add`",
283 },
284 ),
285 msg(
286 "Install the GitCafe CLI with {install}, then run {login}, save a token in Settings, or set {variable} on the server.",
287 {
288 install: "`bun install -g @gitcafe/cli`",
289 login: "`cafe auth login --host https://git.cafe/api`",
290 variable: "CAFE_TOKEN",
291 },
292 ),
293 msg(
294 "Install the TanStack Source CLI with {install}, then run {login}, save a token in Settings, or set {variable} on the server.",
295 {
296 install: "`curl -fsSL https://source.tanstack.com/install | sh`",
297 login: "`src auth login --web --hostname source.tanstack.com`",
298 variable: "SRC_TOKEN",
299 },
300 ),
301];
302​
303/** @public A source-control `installHint`, translated when it is one of the server's fixed hints. */
304export function sourceControlInstallHintText(
305 hint: string,
306 resolve: MFunctionType = mFallback,
307): string {
308 const known = INSTALL_HINTS.find((entry) => mFallback(entry) === hint);
309 return known === undefined ? hint : resolve(known);