Resolves transform options and IDs to canonical transform identifiers.
This module handles the mapping from user-facing options (:from, :to,
:transform, :direction) to the internal transform ID and direction
used by the engine. It also provides conversions between BCP47 (ISO 15924)
script codes and Unicode/CLDR script names.
See the Transform ID resolution section
in Unicode.Transform for a full description of the resolution process.
Summary
Functions
Converts a BCP47 (ISO 15924) script code to its Unicode script name.
Converts a transform ID from BCP47 script codes to CLDR names.
Resolves keyword options to a {transform_id, direction} tuple.
Resolves the target name from an atom or string.
Returns the canonical script name for a script atom.
Converts a transform ID from CLDR names to BCP47 script codes.
Converts a Unicode script name to its BCP47 (ISO 15924) code.
Functions
Converts a BCP47 (ISO 15924) script code to its Unicode script name.
Arguments
code— a BCP47 script code string (e.g.,"Latn","Grek").
Returns
The Unicode script name string if found, or nil.
Examples
iex> Unicode.Transform.Resolve.bcp47_script_to_unicode("Latn")
"Latin"
iex> Unicode.Transform.Resolve.bcp47_script_to_unicode("Grek")
"Greek"
iex> Unicode.Transform.Resolve.bcp47_script_to_unicode("Unknown")
nil
Converts a transform ID from BCP47 script codes to CLDR names.
Replaces each segment of the transform ID that is a known BCP47 script code with its CLDR full name.
Arguments
transform_id— a transform ID string that may contain BCP47 codes.
Returns
The transform ID with BCP47 codes replaced by CLDR names.
Examples
iex> Unicode.Transform.Resolve.resolve_bcp47_transform_id("Grek-Latn")
"Greek-Latin"
iex> Unicode.Transform.Resolve.resolve_bcp47_transform_id("Cyrl-Latn")
"Cyrillic-Latin"
iex> Unicode.Transform.Resolve.resolve_bcp47_transform_id("Latin-ASCII")
"Latin-ASCII"
@spec resolve_options(keyword()) :: {:ok, String.t(), :forward | :reverse} | {:detect, term()} | {:error, term()}
Resolves keyword options to a {transform_id, direction} tuple.
Arguments
options— the keyword list of transform options.
Returns
{:ok, transform_id, direction}when a specific transform is resolved.{:detect, to}when script detection should be used.{:error, reason}on invalid or missing options.
Resolves the target name from an atom or string.
Used when resolving the target for script detection.
Arguments
to— the target as an atom or string.
Returns
The canonical target name string, or {:error, reason}.
Returns the canonical script name for a script atom.
Arguments
atom— a script atom (e.g.,:greek,:grek,:latin).
Returns
The canonical script name string if found, or nil.
Examples
iex> Unicode.Transform.Resolve.script_name(:greek)
"Greek"
iex> Unicode.Transform.Resolve.script_name(:grek)
"Greek"
iex> Unicode.Transform.Resolve.script_name(:unknown_script)
nil
Converts a transform ID from CLDR names to BCP47 script codes.
Replaces each segment of the transform ID that is a known CLDR script name with its BCP47 code.
Arguments
transform_id— a transform ID string that may contain CLDR names.
Returns
The transform ID with CLDR names replaced by BCP47 codes.
Examples
iex> Unicode.Transform.Resolve.to_bcp47_transform_id("Greek-Latin")
"Grek-Latn"
iex> Unicode.Transform.Resolve.to_bcp47_transform_id("Latin-ASCII")
"Latn-ASCII"
iex> Unicode.Transform.Resolve.to_bcp47_transform_id("de-ASCII")
"de-ASCII"
Converts a Unicode script name to its BCP47 (ISO 15924) code.
Arguments
name— a Unicode script name string (e.g.,"Latin","Greek").
Returns
The BCP47 code string if found, or nil.
Examples
iex> Unicode.Transform.Resolve.unicode_script_to_bcp47("Latin")
"Latn"
iex> Unicode.Transform.Resolve.unicode_script_to_bcp47("Greek")
"Grek"
iex> Unicode.Transform.Resolve.unicode_script_to_bcp47("Unknown")
nil