ln-translations is applied to form elements via <form data-ln-translations data-ln-translations-default="en"> to coordinate multi-lingual field editing. It identifies translatable input containers ([data-ln-translatable="field"]), dynamically cloning form controls with deterministic nested naming (e.g. trans[lang][field]) as languages are added. It synchronizes active locale badges and selection menus using <template> elements, submitting localized values natively through the standard HTML form submission pipeline without custom network logic.
In ln-ashlar, this zero-dependency coordinator manages inline multi-lingual inputs by dynamically cloning translatable fields on-demand.
The Translation Mapping Doctrine
A translation utility should only coordinate input fields and serialization layouts. It remains detached from language dictionaries or API translating services. It operates on structured form boundaries, mapping fields dynamically using deterministic HTML attributes. The generated input name attribute is the sole contract.
Key Architectural Advantages
On-Demand Field Cloning: Translatable containers carrying data-ln-translatable serve as templates. When a language is toggled, the coordinator clones the internal input or textarea, sets appropriate placeholder guides, and mounts it cleanly.
Clean Serialization Prefixes: Supports simple fields and complex nested lists. Cloned inputs compile structured array names (e.g. trans[en][title] or items[1][trans][en][title]), allowing standard form submissions to parse arrays natively.
Server & UI Coordination: Detects pre-rendered localized fields on load seamlessly, integrates with `ln-dropdown` to manage locale selection menus, and renders active language badges using standard HTML <template> elements.