Struct representing a language in PhoenixKit.
Provides a consistent data type for all language-related operations, replacing the previous mix of string-keyed and atom-keyed maps.
Fields
code- Language code (e.g., "en-US", "es-ES")name- Full language name (e.g., "English (United States)")native- Native name (e.g., "English (US)")flag- Flag emoji (e.g., "πΊπΈ")is_default- Whether this is the default languageis_enabled- Whether this language is activeposition- Sort position for orderingcountries- List of country names where this language is spoken
Usage
# All Languages module public functions return Language structs:
lang = Languages.get_default_language()
lang.code #=> "en-US"
lang.name #=> "English (United States)"
Summary
Functions
Converts an atom-keyed map (e.g., from BeamLabCountries) to a Language struct.
Converts a string-keyed JSONB map to a Language struct.
Converts a Language struct to a string-keyed map for JSONB storage.
Types
Functions
Converts an atom-keyed map (e.g., from BeamLabCountries) to a Language struct.
Examples
iex> alias PhoenixKit.Modules.Languages.Language
iex> result = Language.from_available_map(%{code: "en-US", name: "English (United States)", native: "English (US)", flag: "πΊπΈ"})
iex> result.code == "en-US" and result.native == "English (US)"
true
Converts a string-keyed JSONB map to a Language struct.
Used when reading language data from database JSON settings.
Examples
iex> alias PhoenixKit.Modules.Languages.Language
iex> result = Language.from_json_map(%{"code" => "en-US", "name" => "English (United States)", "native" => "English (US)", "flag" => "πΊπΈ", "is_default" => true, "position" => 0})
iex> result.code == "en-US" and result.name == "English (United States)" and result.is_default == true
true
Converts a Language struct to a string-keyed map for JSONB storage.
Only includes the fields that are stored in the database JSON config.
Examples
iex> alias PhoenixKit.Modules.Languages.Language
iex> lang = struct(Language, %{code: "en-US", name: "English (United States)", native: "English", flag: "πΊπΈ", is_default: true, is_enabled: true, position: 0, countries: []})
iex> result = Language.to_json_map(lang)
iex> is_map(result) and result["code"] == "en-US" and map_size(result) > 0
true