Skip to content

Document Creator 0.2.10: A language for each template

Document Creator 0.2.10 lets admins tag each template with a language, so a host app can fill the template’s variables in the right language whatever the admin’s own interface language is.

With the Languages module on, each template card and row on the templates tab gets a language picker: Set language until one is chosen, a list of the site’s enabled languages, and Clear language. New templates start with the site’s main language. Documents have no language of their own; they take it from their template. Changes are logged in the activity feed.

The picker relies on CSS anchor positioning, which Firefox does not support yet: there the menu opens away from its button and the picker is not usable.

The admin pages also load faster: the first, not yet connected render no longer queries the database and Google, so those reads now run once per visit instead of twice.

Upgrading

The language column comes from PhoenixKit core’s migration V110 (core 1.7.105 or later): run mix phoenix_kit.update.

Full release notes: Document Creator 0.2.10

0.2.10 · 5 May 2026

Added

  • Per-template :language field — admins tag each template with a locale so parent apps can fill template variables in the matching language regardless of the admin’s UI locale. Stored as a full BCP-47 code (e.g. "en-US", "et-EE", "ja") — what PhoenixKit.Modules.Languages.get_enabled_languages/0 returns; consumers wanting bare base codes can derive via DialectMapper.dialect_to_base/1. Documents intentionally don’t store a language; they inherit from template_uuid → templates.language at fill time. Requires phoenix_kit core ≥ 1.7.105 (V110 column).
  • Documents.update_template_language/3 — set/clear a template’s locale by google_doc_id. Pass nil or "" to clear; otherwise a full locale code. Logs template.language_updated with language_from/language_to metadata; broadcasts :files_changed so connected admin LiveViews resync. Failure-side audit row written on :not_found so the activity feed reflects the attempt.
  • Documents.list_enabled_languages/0 — returns [%{code, name}] sorted by configured position, or [] when PhoenixKit.Modules.Languages is disabled or unreachable. Safe to call from LiveView mount — failure swallowed via narrow rescue clauses.
  • Documents.create_template/2 :language opt — defaults to the project’s primary language from PhoenixKit.Modules.Languages.get_default_language/0; pass nil to leave unset; pass an explicit code to override. Lookup is guarded with rescue + catch :exit so a disabled Languages module never crashes template creation.
  • Schemas.Template.language_changeset/2 — focused single-field changeset honouring validate_length(:language, max: 10). Used by both the create-time language stamp (Documents.create_template/2) and the post-create updater (Documents.update_template_language/3) so both write paths produce a clean {:error, %Ecto.Changeset{}} on oversized codes instead of a Postgrex value too long exception.
  • Per-card popover language picker on the templates LV (card + list views). Native HTML popover API + CSS Anchor Positioning so the menu escapes the card’s overflow: hidden clipping container without bespoke JS. Gated on templates tab + non-trash status + Languages module enabled. Documents tab and trash view do not render the picker.
  • Web.Helpers module — actor_opts/1 and actor_uuid/1 lifted out of duplicated LV-private helpers. Canonical home for future LV cross-cutting helpers.
  • AGENTS.md “Per-template locale” subsection under Public API Layers documenting the V110 schema, the new opts, and the doc-vs-template inheritance rule.

Changed

  • Both admin LiveViews cut over to mount→handle_info. Disconnected mount returns an empty shell with no DB / Settings / Integrations calls; the connected mount subscribes to PubSub (BEFORE the read, closing the broadcast-arrives-between-read-and-subscribe window) then triggers :load_initial/:load_settings to do the file-list reads and the initial Drive sync. Pre-fix the four-call burst per page load (folder_config + active_integration_uuid + list_connections + get_integration + connected? on the settings side; list_*_from_db ×4 + load_cached_thumbnails on the main LV) ran twice per session.
  • discover_folders/0 swapped from bare Task.async/1 ×4 + Task.await_many/2 to Task.Supervisor.async_stream_nolink(PhoenixKit.TaskSupervisor, ...). Caller-LV exit now lets the supervisor clean the children automatically; per-task failure surfaces as {:exit, reason} in the stream so the explicit catch :exit, _ block is gone.
  • verify_known_file/2 is O(1) via MapSet.member?/2 on a known_file_ids assign rebuilt on mount + :sync_complete. Replaces the prior 4× Enum.any?/2 shape (O(N) per event) that was noticeable on folders with thousands of files.
  • Symmetric boot vs lazy legacy-migration paths. Removed the lazy on-read path’s silent “any connected row of this provider” fallback that picked between multi-account installs (a user with google:work AND google:personal who had "google" in settings would have one of those chosen arbitrarily). Both paths now require an exact provider:name match; on no match the setting is cleared and the admin sees a clean “not configured” prompt. Both paths log a warning + activity row on failure so the audit trail covers both outcomes.
  • already_migrated?/0 prefers Integrations.find_uuid_by_provider_name/1 (core 1.7.105+) via a function_exported?/3 runtime guard + apply/3 (the apply/3 dodges the compile-time “undefined function” warning on older cores). Falls back to the legacy provider:name lookup. The fallback can be deleted once ~> 1.7.105 is the floor in mix.exs.
  • Test.StubIntegrations claim/release ownership. Concurrent calls from different live pids raise loudly with :concurrent_stub_use instead of silently racing the named ETS table. Test files using the stub MUST declare async: false. The named ETS table stays (cross-process LV→test boundary requires it) but claim!/0 enforces async-false at runtime.
  • Documents.create_template/2’s create-time language stamp now routes through Template.language_changeset/2 instead of update_all — the V110 max: 10 validation runs on the create path the same way it runs on update_template_language/3. Invalid language is logged and swallowed since the Drive doc is already created at that point; the user can still recover via the post-create picker.
  • LV set_template_language event patches the :templates assign in place via a small patch_template_language/3 helper instead of re-reading the entire list_templates_from_db/0 per click. The self-broadcast is filtered out, so without the in-place patch the badge would lag until the next sync.
  • Test-helper migration cutover. Per dev_docs/migration_cleanup.md, test/test_helper.exs was on the known-buggy Ecto.Migrator.run([{0, PhoenixKit.Migration}], :up, all: true) pattern that silently stopped re-applying once 0 was recorded in schema_migrations. Swapped to PhoenixKit.Migration.ensure_current/2 (core 1.7.105+) which passes a fresh wall-clock version to Ecto.Migrator on every boot.

Fixed

  • M1 (PR #11 follow-up): mount/3 in both LVs no longer queries Settings / Integrations / DB — work moved to a handle_info so the disconnected mount is a fast empty shell and the read-bursts run once per session, not twice.
  • M2 (PR #11 follow-up): Test.StubIntegrations cross-process safety — concurrent stub use across test pids now raises rather than silently racing.
  • S2 / S3 / S5 (PR #11 follow-up): Task supervision, O(1) known-file lookup, helpers extraction (see Changed).
  • §1.2 / §1.3 (PR #12 follow-up): boot-vs-lazy fallback symmetry; uuid-strict already_migrated?/0 (see Changed).
  • Dead _ = changeset line in update_template_language/3’s error branch (no-op carried over from an earlier iteration).

Tests

  • test/schemas/template_test.exs: 6 new tests for the V110 :language field (cast, base + full codes, nil/empty clearing, validate_length boundary), 4 new tests for language_changeset/2 (cast + length + nil + cast-allowlist isolation), and a regression pin that sync_changeset/2 does NOT cast :language.
  • test/integration/documents_test.exs: 9 new tests for Documents.update_template_language/3 — happy path, overwrite, clear (nil + empty string), :not_found error, {:error, changeset} on length validation, activity-log pinning the from→to metadata on success, the failure-side audit row on :not_found, and a PubSub broadcast assertion.
  • test/phoenix_kit_document_creator/web/documents_live_test.exs: 3 new LV tests — verify_known_file rejects unknown ids, the connected-state set_template_language event threads actor_uuid through to the activity row, the clear-language path captures language_from correctly.
  • test/integration/active_integration_test.exs: updated two pre-existing tests to match the new symmetric §1.2 behavior; added a new test for the “no exact match” failure branch.
  • test/support/stub_integrations.ex: get_integration/1 now returns the seeded connection’s data map (matches real PhoenixKit.Integrations response shape) when the requested key matches a seeded {provider, name} pair. Closes a pre-existing footgun where the stub’s degenerate response short-circuited tests meant to exercise exact-match paths.

Known limitations

  • Templates language picker uses CSS Anchor Positioning (anchor-name / position-anchor / position-area) — Chrome/Edge 125+, Safari 26+, not Firefox as of this release. Firefox renders the popover unanchored at the spec-default position (visibility still gated by [&:not(:popover-open)]:hidden so it’s not a blocker, but the picker is unusable on Firefox until anchor positioning ships there).

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