MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / localize

Function localize

packages/sdk/examples/headless-agent.ts:18–33  ·  view source on GitHub ↗
(html: string, translations: Map<string, string>)

Source from the content-addressed store, hash-verified

16// Rewrites all text elements to a new locale. No browser, no preview.
17
18export async function localize(html: string, translations: Map<string, string>): Promise<string> {
19 const comp = await openComposition(html);
20
21 const textElements = comp.find({ tag: "div" });
22
23 comp.batch(() => {
24 for (const id of textElements) {
25 const el = comp.getElement(id);
26 if (!el?.text) continue;
27 const translated = translations.get(el.text);
28 if (translated) comp.setText(id, translated);
29 }
30 });
31
32 return comp.serialize();
33}
34
35// ── Brand restyle agent ───────────────────────────────────────────────────────
36// Apply brand colors to all elements with a matching class name.

Callers

nothing calls this directly

Calls 7

openCompositionFunction · 0.85
getMethod · 0.80
findMethod · 0.65
batchMethod · 0.65
getElementMethod · 0.65
setTextMethod · 0.65
serializeMethod · 0.65

Tested by

no test coverage detected