Skip to content

Entities 0.2.10: Translations no longer lost when a record is edited

Entities 0.2.10 fixes a data-loss bug in the admin record form on multi-language sites. Every language tab showed the same text, and saving the record deleted all its other translations.

The form loaded the record already merged into the admin’s own interface language, so the other languages were no longer there. All tabs showed that one language, and the next save wrote it back as the only one. A record in four languages edited once came back with one. The form now loads the record with all its languages, both when it opens and when it refreshes after a change elsewhere.

Sites that once had several languages and later turned the Languages module off had two more problems with such records: the form showed every field blank and then saved the blanks over the main language, and saved values could land under no language at all. The form now reads and saves the record’s main language.

The module also reports its version correctly again; it said 0.1.4.

Full release notes: Entities 0.2.10

0.2.10 · 29 July 2026

Fixed

  • The admin data form showed one language in every language tab, and deleted the rest on save. Web.DataForm.handle_params/3 loaded the record with EntityData.get!(uuid, lang: locale), where locale is the admin’s own UI locale. That option runs resolve_language/2, which replaces the multilang data JSONB with the single merged map for that locale — _primary_language and every other language are gone from the struct. Two consequences, both reported as “translations aren’t in the admin, but they’re in the DB”:

    • Every language tab rendered the same text. MultilangForm.get_lang_data/3 asks Multilang.get_raw_language_data/2 for the tab’s language; on a flattened map that returns the whole map regardless of which language was asked for, so all tabs showed whatever the admin’s UI locale resolved to.
    • The next save wrote the collapsed map back. merge_multilang_data/4 builds the new data from this changeset, so put_language_data/3 saw non-multilang data, rebuilt the structure around a single language, and the row lost the others permanently. A four-language record edited once came back with one.

    The record is now loaded raw at all three sites (both handle_params/3 edit clauses and the :data_updated refresh in handle_info/2). The entity is still loaded with :lang — that only localises display_name/description for the admin chrome and leaves fields_definition alone.

  • Web.DataForm no longer merges submitted values under a nil language key when the Languages module is disabled but the row still carries multilang data (languages configured once, later switched off). current_lang is nil in that state; the new merge_lang/2 falls back to the row’s embedded _primary_language. Flat rows are unaffected — they have no embedded primary, so the merge keeps passing params straight through.

  • The single-language layout rendered every custom field blank over a multilang row, then saved the blanks over the primary language. Same state as above (Languages module off, row still multilang), on the read side: that layout calls FormBuilder.build_fields/3 with lang_code: nil, so each field reads data["field_key"] straight off the changeset — one level above where a multilang row keeps its values. The fields came up empty, and the following save merged those blanks under the embedded primary via merge_lang/2, replacing that language’s real content. The new primary_language_view/1 hands the layout a flattened primary-language view to read from; input names are unchanged, so params still round-trip back under the primary key. Flat rows pass through untouched.

Changed

  • EntityData.resolve_language/2 is documented as lossy and display-only, with an explicit warning never to build an update changeset from its result. list_tree/2’s :lang option points at it.

Entities 0.2.10. Install or update: {:phoenix_kit_entities, "~> 0.2"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.