Loads CLDR transform definitions from XML files.
Uses SweetXml to parse the XML and extract the transform metadata and rule text.
Summary
Functions
Builds the alias index from all transform XML files and stores
it in a persistent_term. Called at application startup to
avoid lazy initialization on the first transform call.
Finds the XML file path and direction for a given transform ID.
Lists all available transform XML files.
Loads a transform definition from an XML file.
Derives a transform ID from source and target.
Derives a transform ID from a filename.
Returns the default transforms directory path.
Functions
@spec build_alias_index() :: map()
Builds the alias index from all transform XML files and stores
it in a persistent_term. Called at application startup to
avoid lazy initialization on the first transform call.
Returns
The alias index map.
Finds the XML file path and direction for a given transform ID.
Resolves transform names by checking:
Exact filename match (e.g.,
"Latin-ASCII"→"priv/transforms/Latin-ASCII.xml").Forward alias match from XML metadata.
Backward alias match from XML metadata.
Reverse direction lookup (e.g.,
"ConjoiningJamo-Latin"found via"Latin-ConjoiningJamo.xml"withdirection="both").BCP47 (ISO 15924) script code resolution (e.g.,
"Grek-Latn"→"Greek-Latin").
Arguments
transform_id— the transform name to resolve.
Returns
{file_path, :forward}— use the file's rules in forward direction.{file_path, :backward}— use the file's rules in backward/reverse direction.nil— no matching transform found.
@spec list_transforms() :: [Path.t()]
Lists all available transform XML files.
Returns
A list of file paths to transform XML files.
Loads a transform definition from an XML file.
Arguments
file_path— path to the XML file.
Returns
A map with the following keys:
:source— source script/locale.:target— target script/locale.:direction—"forward","backward", or"both".:alias— transform alias string.:backward_alias— backward transform alias string.:rules— the raw rule text string.
Derives a transform ID from source and target.
Arguments
source— the source script name.target— the target script name.
Returns
A string like "Latin-ASCII" or "Greek-Latin".
Derives a transform ID from a filename.
Arguments
file_path— the path to the XML file.
Returns
A string transform ID derived from the filename.
@spec transforms_dir() :: Path.t()
Returns the default transforms directory path.
Returns
The path to the transforms directory.