gt@2.12.0
Overview
derive() can now resolve values from objects and arrays — not just function return values. The same support extends to Python's derive() with dictionaries and lists. This means the CLI can statically extract all possible string variants from data structures at build time, creating a separate translation entry for each one.
This builds on the tagged template support for derive() added in gt-react@10.15.0.
Object and array access
Given an object of string variants, derive() extracts every value:
const labels = { success: "Saved", error: "Failed", pending: "Saving..." };
t`Status: ${derive(labels[status])}`;The CLI resolves all three values and registers separate translation entries for each.
This works with both computed access (obj[key]) and static access (obj.prop), and supports nesting:
const messages = {
greeting: { formal: "Good evening", casual: "Hey" },
farewell: { formal: "Goodbye", casual: "See ya" },
};
t`${derive(messages[category][tone])}`;Arrays work the same way:
const ranks = ["Bronze", "Silver", "Gold", "Platinum"];
t`Your rank: ${derive(ranks[level])}`;Python
The same object/array resolution works in Python with dictionaries and lists:
labels = { "success": "Saved", "error": "Failed" }
t("{status}", status=derive(labels[status_key]))ranks = ["Bronze", "Silver", "Gold", "Platinum"]
t("{rank}", rank=derive(ranks[level]))Requirements
- Objects and arrays must be declared with
const(TypeScript) or at module level (Python). - Spread syntax (
...base) is supported and flattened at extraction time. - TypeScript annotations (
as const,satisfies) are unwrapped automatically. - Circular spreads are detected and produce a warning instead of hanging.