language_switcher_dialog
A modern language switcher for Drupal that replaces the default language block with a trigger button + modal dialog pattern. Built on the native HTML <dialog> element and Drupal core's HTMX integration. No jQuery UI, no custom focus-trap libraries, no JavaScript frameworks.
Designed for WCAG 2.2 AA compliance out of the box.
How it works
The module places a block with a compact trigger button showing the current language. Clicking it opens a modal dialog that loads language switch links via HTMX. The dialog content is lazy-loaded as an HTML fragment: no JSON, no client-side rendering.
Key features
- Native
<dialog>withshowModal(): built-in focus trapping, Escape key dismissal, and background inertness without custom JavaScript - HTMX-powered: uses Drupal 11.3's
core/drupal.htmxlibrary for server-rendered HTML fragment loading - Pluggable dialog content: a Drupal plugin system lets you swap out how language links are rendered, or create your own
- No CSS by default: bring your own theme styles. An optional "classic dialog" CSS library is included for quick prototyping
- Accessible: proper focus management, ARIA attributes,
hreflang/langon links, CSStext-transformfor uppercase,prefers-reduced-motionandforced-colorssupport
Included submodules
Language Switcher Dialog: Countries
Maps languages to countries and world regions. Adds country code, base language code, and region fields to each language configuration entity.
Ships two dialog content provider plugins:
- Enhanced links: a flat list of language links enriched with country names and optional flag icons
- Grouped by region: languages organized under region headings (Europe, Asia, etc.)
Also adds country-aware trigger button formats (e.g. "BE - NL", "Belgium - Dutch") and extends the trigger with optional flag icons.
Requires the Country module. Optionally integrates with Flags for country flag icons.
Language Switcher Dialog: GeoIP
Shows a one-time language suggestion popup for first-time visitors based on their IP-detected country. The popup is loaded via HTMX, uses a server-side cookie check to avoid repeat prompts, and includes configurable bot detection to skip search engine crawlers.
Requires the Countries submodule and Smart IP.
Requirements
- Drupal 11.3+ (for core HTMX support)
- PHP 8.3+
- Core Language module with two or more languages configured
Extending
The module is designed to be extended without patching:
- Dialog content provider plugins: drop a plugin class in
Plugin/DialogContentProvider/and it's auto-discovered in the settings form - Alter hooks: customize trigger button formats, world regions, GeoIP bot patterns, and plugin definitions
- Template overrides: all templates follow standard Drupal theme suggestion patterns
See language_switcher_dialog.api.php for documented hook signatures.
🤖 Assisted Development
This module is maintained with the help of AI assistants for code generation, review, testing, and documentation. All code is carefully reviewed by the maintainers to ensure that quality and security standards are met.