PhoenixKitWeb.Components.Core.LanguageSwitcher (phoenix_kit v1.7.38)

Copy Markdown View Source

Language switcher component for frontend applications.

Provides a reusable language selection dropdown that pulls available languages from the Language Module. Supports multiple display styles and configurations.

Examples

# Basic dropdown switcher
<.language_switcher_dropdown current_locale={@current_locale} />

# Button group switcher (for mobile)
<.language_switcher_buttons current_locale={@current_locale} />

# Inline switcher with flags
<.language_switcher_inline current_locale={@current_locale} />

Attributes

  • current_locale - Current active language code (e.g., "en", "es")
  • style - Display style: :dropdown, :buttons, :inline (default: :dropdown)
  • class - Additional CSS classes to apply
  • show_flags - Show language flags (default: true)
  • show_native_names - Show native language names (default: false)

Summary

Functions

Renders a button group language switcher.

Renders a dropdown language switcher.

Renders an inline language switcher.

Functions

language_switcher_buttons(assigns)

Renders a button group language switcher.

Displays language buttons in a row. Good for mobile layouts and areas where space allows for multiple buttons. Automatically fetches the configured languages (or default top 12 if not configured).

Examples

<.language_switcher_buttons current_locale={@current_locale} />

Attributes

  • current_locale (:string) - Current active language code (auto-detected if not provided). Defaults to nil.
  • languages (:any) - List of language maps. If nil, fetches from Language Module. Defaults to nil.
  • show_flags (:boolean) - Show language flags. Defaults to true.
  • show_names (:boolean) - Show language names. Defaults to true.
  • goto_home (:boolean) - Redirect to home page on language switch. Defaults to false.
  • hide_current (:boolean) - Hide currently selected language from list. Defaults to false.
  • class (:string) - Additional CSS classes. Defaults to "".
  • current_path (:string) - Current path to preserve when switching languages. Defaults to nil.

language_switcher_dropdown(assigns)

Renders a dropdown language switcher.

Displays a globe icon that opens a dropdown menu with available languages. Automatically fetches the configured languages (or default top 12 if not configured). Perfect for navigation bars and header areas.

Examples

<.language_switcher_dropdown current_locale={@current_locale} />

<.language_switcher_dropdown
  current_locale={@current_locale}
  show_native_names={true}
/>

Attributes

  • current_locale (:string) - Current active language code (auto-detected if not provided). Defaults to nil.
  • languages (:any) - List of language maps. If nil, fetches from Language Module. Defaults to nil.
  • show_flags (:boolean) - Show language flags. Defaults to true.
  • show_names (:boolean) - Show language names. Defaults to true.
  • show_native_names (:boolean) - Show native language names. Defaults to false.
  • goto_home (:boolean) - Redirect to home page on language switch. Defaults to false.
  • hide_current (:boolean) - Hide currently selected language from list. Defaults to false.
  • class (:string) - Additional CSS classes. Defaults to "".
  • current_path (:string) - Current path to preserve when switching languages. Defaults to nil.
  • scroll_threshold (:integer) - Number of languages after which to show scrollbar and search. Defaults to 10.
  • show_current (:boolean) - Show current language (flag + name) in dropdown trigger instead of globe icon. Defaults to false.
  • _language_update_key (:any) - Internal: forces re-render when languages change. Defaults to nil.

language_switcher_inline(assigns)

Renders an inline language switcher.

Displays languages as inline text links. Minimal design perfect for footers or compact navigation areas. Automatically fetches the configured languages (or default top 12 if not configured).

Examples

<.language_switcher_inline current_locale={@current_locale} />

Attributes

  • current_locale (:string) - Current active language code (auto-detected if not provided). Defaults to nil.
  • languages (:any) - List of language maps. If nil, fetches from Language Module. Defaults to nil.
  • show_flags (:boolean) - Show language flags. Defaults to true.
  • show_names (:boolean) - Show language names. Defaults to true.
  • goto_home (:boolean) - Redirect to home page on language switch. Defaults to false.
  • hide_current (:boolean) - Hide currently selected language from list. Defaults to false.
  • class (:string) - Additional CSS classes. Defaults to "".
  • current_path (:string) - Current path to preserve when switching languages. Defaults to nil.