Unicode.Transform.Loader (Unicode Transform v1.1.0)

Copy Markdown View Source

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

build_alias_index()

@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.

find_transform(transform_id)

@spec find_transform(String.t()) :: {Path.t(), :forward | :backward} | nil

Finds the XML file path and direction for a given transform ID.

Resolves transform names by checking:

  1. Exact filename match (e.g., "Latin-ASCII""priv/transforms/Latin-ASCII.xml").

  2. Forward alias match from XML metadata.

  3. Backward alias match from XML metadata.

  4. Reverse direction lookup (e.g., "ConjoiningJamo-Latin" found via "Latin-ConjoiningJamo.xml" with direction="both").

  5. 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.

list_transforms()

@spec list_transforms() :: [Path.t()]

Lists all available transform XML files.

Returns

A list of file paths to transform XML files.

load_file(file_path)

@spec load_file(Path.t()) :: map()

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.

transform_id(source, target)

@spec transform_id(String.t(), String.t()) :: String.t()

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".

transform_id_from_file(file_path)

@spec transform_id_from_file(Path.t()) :: String.t()

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.

transforms_dir()

@spec transforms_dir() :: Path.t()

Returns the default transforms directory path.

Returns

The path to the transforms directory.