Skip to content

Commit c3cb3cc

Browse files
I18n: Standardize using t() function (anomalyco#1639)
* Cleanup usage of I18n function * Add skip pattern * Cleanup I18n function usage across react-app Drop translate/tr alias wrappers that just forwarded to t() with an explicit locale arg, and migrate direct t(key, locale, ...) calls to the new t(key, params?) signature. Also drop the now-unused language prop drilled through McpAuthModal, AddMcpModal, ControlChromeSetupModal, and the translate prop drilled through CreateWorkspaceLocalPanel — components read the global locale via t() directly. Default the i18n-audit script to include --aliases. * Collapse single-key t() calls onto one line The translate() → t() rename left multi-line wrappers around short string literals. Re-flow them since the longer translate() name is gone. * Fix useTranslate hook for new t() signature Dev's redesign reintroduced tr/tx wrappers via a centralized useTranslate hook, but the hook calls t(key, currentLocale(), params) — the old 3-argument signature. The current 2-argument t(key, params) silently drops the third arg, so every tx() call would lose its substitutions (e.g. {name}/{count} placeholders never get replaced). Drop currentLocale() — t() uses the current locale by default — and pass params straight through.
1 parent a41c464 commit c3cb3cc

30 files changed

Lines changed: 527 additions & 589 deletions

‎apps/app/src/app/lib/model-behavior.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const getVariantDescription = (
143143
if (key === "xhigh" || key === "max") return family === "anthropic"
144144
? t("model_behavior.desc_max_anthropic")
145145
: t("model_behavior.desc_max");
146-
return t("model_behavior.desc_generic", undefined, { label: label.toLowerCase() });
146+
return t("model_behavior.desc_generic", { label: label.toLowerCase() });
147147
};
148148

149149
export const getModelBehaviorOptions = (

‎apps/app/src/app/utils/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ export function formatRelativeTime(timestampMs: number) {
269269
}
270270

271271
if (delta < 60_000) {
272-
return t("time.seconds_ago", undefined, { count: Math.max(1, Math.round(delta / 1000)) });
272+
return t("time.seconds_ago", { count: Math.max(1, Math.round(delta / 1000)) });
273273
}
274274

275275
if (delta < 60 * 60_000) {
276-
return t("time.minutes_ago", undefined, { count: Math.max(1, Math.round(delta / 60_000)) });
276+
return t("time.minutes_ago", { count: Math.max(1, Math.round(delta / 60_000)) });
277277
}
278278

279279
if (delta < 24 * 60 * 60_000) {
280-
return t("time.hours_ago", undefined, { count: Math.max(1, Math.round(delta / (60 * 60_000))) });
280+
return t("time.hours_ago", { count: Math.max(1, Math.round(delta / (60 * 60_000))) });
281281
}
282282

283283
return new Date(timestampMs).toLocaleDateString();

‎apps/app/src/hooks/use-translate.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as React from "react";
2-
import { currentLocale, t } from "@/i18n";
2+
import { t } from "@/i18n";
33

44
export function useTranslate() {
5-
const tr = React.useCallback((key: string) => t(key, currentLocale()), []);
5+
const tr = React.useCallback((key: string) => t(key), []);
66
const tx = React.useCallback(
7-
(key: string, params?: Record<string, string | number>) =>
8-
t(key, currentLocale(), params),
7+
(key: string, params?: Record<string, string | number>) => t(key, params),
98
[],
109
);
1110

‎apps/app/src/i18n/index.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export const setLocale = (newLocale: Language) => {
101101
* @param localeOverride - Optional locale override (defaults to current locale)
102102
* @returns Translated string or fallback
103103
*/
104-
export const t = (key: string, localeOverride?: Language, params?: Record<string, string | number>): string => {
105-
const loc = localeOverride ?? locale();
104+
export const t = (key: string, params?: Record<string, string | number> & { lng?: Language }): string => {
105+
const loc = params?.lng ?? locale();
106106

107107
// Try target language first
108108
let result: string;
@@ -116,9 +116,10 @@ export const t = (key: string, localeOverride?: Language, params?: Record<string
116116
return key;
117117
}
118118

119-
// Replace params if provided
119+
// Replace params if provided (skip the lng meta-key)
120120
if (params) {
121121
for (const [k, v] of Object.entries(params)) {
122+
if (k === "lng") continue;
122123
result = result.replace(`{${k}}`, String(v));
123124
}
124125
}

‎apps/app/src/react-app/design-system/restriction-notice-modal.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @jsxImportSource react */
22
import { X } from "lucide-react";
33

4-
import { currentLocale, t } from "../../i18n";
4+
import { t } from "../../i18n";
55
import { Button } from "./button";
66

77
export type RestrictionNoticeModalProps = {
@@ -35,7 +35,7 @@ export function RestrictionNoticeModal(props: RestrictionNoticeModalProps) {
3535
<button
3636
type="button"
3737
className="inline-flex h-9 w-9 items-center justify-center rounded-full text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text"
38-
aria-label={t("common.close", currentLocale())}
38+
aria-label={t("common.close")}
3939
onClick={props.onClose}
4040
>
4141
<X size={18} />
@@ -48,7 +48,7 @@ export function RestrictionNoticeModal(props: RestrictionNoticeModalProps) {
4848
</p>
4949
<div className="mt-6 flex justify-end">
5050
<Button variant="primary" onClick={props.onClose}>
51-
{t("common.close", currentLocale())}
51+
{t("common.close")}
5252
</Button>
5353
</div>
5454
</div>

‎apps/app/src/react-app/domains/bundles/skill-destination-modal.tsx‎

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "lucide-react";
1212

1313
import type { WorkspaceInfo } from "../../../app/lib/desktop";
14-
import { currentLocale, t } from "../../../i18n";
14+
import { t } from "../../../i18n";
1515
import { isSandboxWorkspace } from "../../../app/utils";
1616
import { Button } from "../../design-system/button";
1717

@@ -43,7 +43,6 @@ const displayName = (workspace: WorkspaceInfo, fallback: string): string =>
4343
fallback;
4444

4545
export function SkillDestinationModal(props: SkillDestinationModalProps) {
46-
const translate = (key: string) => t(key, currentLocale());
4746
const [selectedWorkspaceId, setSelectedWorkspaceId] = useState<
4847
string | null
4948
>(null);
@@ -72,26 +71,26 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
7271
if (workspace.workspaceType === "local") {
7372
return (
7473
workspace.path?.trim() ||
75-
translate("share_skill_destination.local_badge")
74+
t("share_skill_destination.local_badge")
7675
);
7776
}
7877
return (
7978
workspace.directory?.trim() ||
8079
workspace.openworkHostUrl?.trim() ||
8180
workspace.baseUrl?.trim() ||
8281
workspace.path?.trim() ||
83-
translate("share_skill_destination.remote_badge")
82+
t("share_skill_destination.remote_badge")
8483
);
8584
};
8685

8786
const workspaceBadge = (workspace: WorkspaceInfo): string => {
8887
if (isSandboxWorkspace(workspace)) {
89-
return translate("share_skill_destination.sandbox_badge");
88+
return t("share_skill_destination.sandbox_badge");
9089
}
9190
if (workspace.workspaceType === "remote") {
92-
return translate("share_skill_destination.remote_badge");
91+
return t("share_skill_destination.remote_badge");
9392
}
94-
return translate("share_skill_destination.local_badge");
93+
return t("share_skill_destination.local_badge");
9594
};
9695

9796
const workspaceCircleClass = (
@@ -126,7 +125,7 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
126125
<div className="min-w-0 space-y-3">
127126
<div className="inline-flex items-center gap-2 rounded-full border border-gray-6 bg-gray-2 px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.18em] text-gray-10">
128127
<Sparkles size={12} />
129-
{translate("share_skill_destination.skill_label")}
128+
{t("share_skill_destination.skill_label")}
130129
</div>
131130
<div className="rounded-xl border border-gray-6 bg-gray-2/40 px-4 py-4">
132131
<div className="flex items-start gap-3">
@@ -135,11 +134,11 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
135134
</div>
136135
<div className="min-w-0 flex-1">
137136
<div className="text-[11px] font-semibold uppercase tracking-[0.18em] text-gray-9">
138-
{translate("share_skill_destination.skill_label")}
137+
{t("share_skill_destination.skill_label")}
139138
</div>
140139
<h3 className="mt-1 text-lg font-semibold text-gray-12 break-words">
141140
{props.skill?.name ??
142-
translate("share_skill_destination.fallback_skill_name")}
141+
t("share_skill_destination.fallback_skill_name")}
143142
</h3>
144143
{props.skill?.description?.trim() ? (
145144
<p className="mt-1 text-sm leading-relaxed text-gray-10 break-words">
@@ -149,7 +148,7 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
149148
{props.skill?.trigger?.trim() ? (
150149
<div className="mt-3 inline-flex items-center gap-2 rounded-full border border-gray-6 bg-gray-1 px-3 py-1 text-[11px] text-gray-10">
151150
<span className="font-semibold text-gray-12">
152-
{translate("share_skill_destination.trigger_label")}
151+
{t("share_skill_destination.trigger_label")}
153152
</span>
154153
<span className="font-mono">
155154
{props.skill.trigger.trim()}
@@ -161,10 +160,10 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
161160
</div>
162161
<div>
163162
<h4 className="text-sm font-medium text-gray-12">
164-
{translate("share_skill_destination.title")}
163+
{t("share_skill_destination.title")}
165164
</h4>
166165
<p className="mt-1 text-sm leading-relaxed text-gray-10">
167-
{translate("share_skill_destination.subtitle")}
166+
{t("share_skill_destination.subtitle")}
168167
</p>
169168
</div>
170169
</div>
@@ -175,7 +174,7 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
175174
className={`rounded-full p-2 text-gray-9 transition hover:bg-gray-2 hover:text-gray-12 ${
176175
footerBusy ? "cursor-not-allowed opacity-50" : ""
177176
}`.trim()}
178-
aria-label={translate("common.close")}
177+
aria-label={t("common.close")}
179178
>
180179
<X size={18} />
181180
</button>
@@ -186,7 +185,7 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
186185
<div className="space-y-3">
187186
<div className="flex items-center justify-between gap-3">
188187
<div className="text-sm font-medium text-gray-12">
189-
{translate("share_skill_destination.existing_workers")}
188+
{t("share_skill_destination.existing_workers")}
190189
</div>
191190
{props.workspaces.length > 0 ? (
192191
<span className="text-[11px] uppercase tracking-[0.18em] text-gray-9">
@@ -197,7 +196,7 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
197196

198197
{props.workspaces.length === 0 ? (
199198
<div className="rounded-xl border border-dashed border-gray-6 bg-gray-2/20 px-4 py-5 text-sm leading-relaxed text-gray-10">
200-
{translate("share_skill_destination.no_workers")}
199+
{t("share_skill_destination.no_workers")}
201200
</div>
202201
) : (
203202
<div className="space-y-2">
@@ -240,17 +239,15 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
240239
</div>
241240
{isActive ? (
242241
<span className="rounded-full bg-gray-3 px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-gray-11">
243-
{translate("share_skill_destination.current_badge")}
242+
{t("share_skill_destination.current_badge")}
244243
</span>
245244
) : null}
246245
<span className="rounded-full bg-gray-3 px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-gray-11">
247246
{workspaceBadge(workspace)}
248247
</span>
249248
{isSelected ? (
250249
<span className="rounded-full bg-indigo-3/60 px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-indigo-11">
251-
{translate(
252-
"share_skill_destination.selected_badge",
253-
)}
250+
{t("share_skill_destination.selected_badge")}
254251
</span>
255252
) : null}
256253
</div>
@@ -260,9 +257,7 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
260257
</div>
261258
{isSelected ? (
262259
<div className="mt-2 text-xs font-medium text-gray-11">
263-
{translate(
264-
"share_skill_destination.selected_hint",
265-
)}
260+
{t("share_skill_destination.selected_hint")}
266261
</div>
267262
) : null}
268263
</div>
@@ -290,7 +285,7 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
290285
{props.onCreateWorker || props.onConnectRemote ? (
291286
<div className="space-y-3 border-t border-gray-6 pt-5">
292287
<div className="text-sm font-medium text-gray-12">
293-
{translate("share_skill_destination.more_options")}
288+
{t("share_skill_destination.more_options")}
294289
</div>
295290
<div className="grid gap-3 md:grid-cols-2">
296291
{props.onCreateWorker ? (
@@ -308,12 +303,10 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
308303
</div>
309304
<div>
310305
<div className="text-sm font-semibold text-gray-12">
311-
{translate("share_skill_destination.create_worker")}
306+
{t("share_skill_destination.create_worker")}
312307
</div>
313308
<div className="mt-1 text-sm text-gray-10">
314-
{translate(
315-
"share_skill_destination.create_worker_hint",
316-
)}
309+
{t("share_skill_destination.create_worker_hint")}
317310
</div>
318311
</div>
319312
</div>
@@ -335,12 +328,10 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
335328
</div>
336329
<div>
337330
<div className="text-sm font-semibold text-gray-12">
338-
{translate("share_skill_destination.connect_remote")}
331+
{t("share_skill_destination.connect_remote")}
339332
</div>
340333
<div className="mt-1 text-sm text-gray-10">
341-
{translate(
342-
"share_skill_destination.connect_remote_hint",
343-
)}
334+
{t("share_skill_destination.connect_remote_hint")}
344335
</div>
345336
</div>
346337
</div>
@@ -371,7 +362,7 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
371362
onClick={props.onClose}
372363
disabled={footerBusy}
373364
>
374-
{translate("common.cancel")}
365+
{t("common.cancel")}
375366
</Button>
376367
<Button
377368
variant="primary"
@@ -381,10 +372,10 @@ export function SkillDestinationModal(props: SkillDestinationModalProps) {
381372
{footerBusy ? (
382373
<span className="inline-flex items-center gap-2">
383374
<Loader2 size={16} className="animate-spin" />
384-
{translate("share_skill_destination.adding")}
375+
{t("share_skill_destination.adding")}
385376
</span>
386377
) : (
387-
translate("share_skill_destination.add_to_workspace")
378+
t("share_skill_destination.add_to_workspace")
388379
)}
389380
</Button>
390381
</div>

0 commit comments

Comments
 (0)