PhoenixKit.Modules.Publishing.Web.Components.LanguageSwitcher (phoenix_kit v1.7.33)

Copy Markdown View Source

Unified language switcher component for publishing posts.

Displays available languages as a compact inline list with status indicators. Flexible enough for admin interfaces (with status dots) and public pages (links only).

Display Format

Admin mode: ● EN | ● FR | ○ ES

  • Green dot (●): Published
  • Yellow dot (●): Draft
  • Gray dot (●): Archived
  • Empty dot (○): No translation exists

Public mode: EN | FR | ES

  • No status indicators
  • Only shows languages with published translations

Examples

# Admin: publishing listing with edit links and status indicators
<.publishing_language_switcher
  languages={@languages}
  current_language="en"
  on_click="switch_language"
  show_status={true}
/>

# Admin: editor with switch functionality
<.publishing_language_switcher
  languages={@languages}
  current_language={@current_language}
  on_click="switch_language"
  show_status={true}
  show_add={true}
/>

# Public: post page with translation links
<.publishing_language_switcher
  languages={@translations}
  current_language={@current_language}
  show_status={false}
/>

Summary

Functions

Renders a compact inline language switcher.

Functions

publishing_language_switcher(assigns)

Renders a compact inline language switcher.

Attributes

  • languages - List of language maps with keys: code, name, status, url, exists
  • current_language - Currently active language code
  • show_status - Show status indicator dots (default: true)
  • show_add - Show "add" option for missing languages (default: false)
  • show_flags - Show flag emojis (default: false)
  • on_click - Event name for click handler (optional, uses href if not provided)
  • class - Additional CSS classes
  • size - Size variant: :xs, :sm, :md (default: :sm)

Language Map Structure

Each language in the list should have:

  • code - Language code (e.g., "en", "fr")
  • name - Display name (e.g., "English", "French") - optional
  • flag - Flag emoji (e.g., "🇺🇸") - optional
  • status - Post status: "published", "draft", "archived", or nil if not exists
  • url - URL to navigate to (for public mode or href navigation)
  • exists - Boolean, whether translation file exists (default: inferred from status)
  • enabled - Boolean, whether the language is enabled in the Languages module (default: true)
  • known - Boolean, whether the language code is recognized (default: true)

Attributes

  • languages (:list) (required)
  • current_language (:string) - Defaults to nil.
  • show_status (:boolean) - Defaults to true.
  • show_add (:boolean) - Defaults to false.
  • show_flags (:boolean) - Defaults to false.
  • on_click (:string) - Defaults to nil.
  • phx_target (:any) - Defaults to nil.
  • class (:string) - Defaults to "".
  • size (:atom) - Defaults to :sm. Must be one of :xs, :sm, or :md.