Translations

Mode

Skin

Theme

Overview & Philosophy

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

  1. 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.
  2. 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.
  3. 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.

For the full guide see the ln-translations README and the architecture reference.

Basics

AttributeOn elementDescription
data-ln-translations<form>Initializes instance
data-ln-translations-default<form>Default language code (flag on originals)
data-ln-translations-add<button>Trigger button (inside data-ln-dropdown)
data-ln-translations-active<ul>Container for active language badges
data-ln-translatable="field"wrapperMarks a translatable field
data-ln-translations-prefixwrapperNested prefix for name attr
data-ln-translatable-langinput/textareaLanguage code (set by JS or server)

Example — Basic

Company Info

      Example — With Existing Translations

      Standard Details

          Example — Nested Items (Prefix)

          Checklist Items

              API & Events

              Instance API

              const el = document.querySelector('[data-ln-translations]');
              el.lnTranslations.addLanguage('en');
              el.lnTranslations.addLanguage('sq', { scope: 'Prodhimi...' });
              el.lnTranslations.removeLanguage('en');
              el.lnTranslations.hasLanguage('en');          // boolean
              el.lnTranslations.getActiveLanguages();       // Set

              Events

              EventBubblesCancelableDetail
              ln-translations:before-addyesyes{ target, lang, langName }
              ln-translations:addedyesno{ target, lang, langName }
              ln-translations:before-removeyesyes{ target, lang }
              ln-translations:removedyesno{ target, lang }
              ln-translations:request-addnono{ lang }
              ln-translations:request-removenono{ lang }

              Name Generation

              // Without prefix:
              name="trans[en][scope]"
              
              // With prefix (data-ln-translations-prefix="items[5]"):
              name="items[5][trans][en][title]"