Pure language utility functions for the Publishing module.
Provides language detection, display ordering, language info lookup, and primary language management.
Summary
Functions
Returns all enabled language codes for multi-language support. Falls back to content language if Languages module is disabled.
Determines the display code for a language based on whether multiple dialects of the same base language are enabled.
Gets language details (name, flag) for a given language code.
Returns the primary/canonical language for versioning. Uses Settings.get_content_language().
Checks if a language code is enabled, considering base code matching.
Orders languages for display in the language switcher.
Checks if a language code is reserved (cannot be used as a slug).
Functions
@spec enabled_language_codes() :: [String.t()]
Returns all enabled language codes for multi-language support. Falls back to content language if Languages module is disabled.
Determines the display code for a language based on whether multiple dialects of the same base language are enabled.
If only one dialect of a base language is enabled (e.g., just "en-US"), returns the base code ("en") for cleaner display.
If multiple dialects are enabled (e.g., "en-US" and "en-GB"), returns the full dialect code ("en-US") to distinguish them.
@spec get_language_info(String.t()) :: %{code: String.t(), name: String.t(), flag: String.t()} | nil
Gets language details (name, flag) for a given language code.
Searches in order:
- Predefined languages (BeamLabCountries) - for full locale details
- User-configured languages - for custom/less common languages
@spec get_primary_language() :: String.t()
Returns the primary/canonical language for versioning. Uses Settings.get_content_language().
Checks if a language code is enabled, considering base code matching.
Handles cases where:
- The code is
enand enabled languages has"en-US"-> matches - The code is
en-USand enabled languages has"en"-> matches
Orders languages for display in the language switcher.
Order: primary language first, then languages with translations (sorted), then languages without translations (sorted).
Checks if a language code is reserved (cannot be used as a slug).