Cldr.Collation.Tailoring (Cldr Collation v1.1.0)

Copy Markdown View Source

CLDR locale-specific collation tailoring.

Parses and applies CLDR tailoring rules that modify the root collation order for specific locales. Rules use the ICU/CLDR syntax defined in UTS #35:

  • &X — reset position to after character X.

  • &[before N]X — reset to just before X at level N.

  • < — primary difference (new letter).

  • << — secondary difference (accent variant).

  • <<< — tertiary difference (case variant).

  • [caseFirst upper] — option overrides.

Tailoring data is embedded directly from CLDR XML sources, covering common European and Asian locales.

Summary

Functions

Get a tailoring overlay for the given locale and collation type.

Parse a CLDR tailoring rule string into a list of operations.

List all supported locale/type combinations.

Functions

get_tailoring(language, type)

@spec get_tailoring(String.t(), atom()) :: {map(), keyword()} | nil

Get a tailoring overlay for the given locale and collation type.

Parses the CLDR tailoring rules and computes overlay entries that modify the root collation table for locale-specific ordering.

Arguments

  • language - ISO 639 language code (e.g., "sv", "de", "es").
  • type - collation type atom (e.g., :standard, :phonebook, :traditional).

Returns

  • {overlay, option_overrides} - a map of %{[codepoint] => [%Element{}]} overlay entries. and a keyword list of option overrides (e.g., [case_first: :upper])
  • nil - if no tailoring exists for the given locale and type.

Examples

iex> Cldr.Collation.Table.ensure_loaded()
iex> {overlay, _opts} = Cldr.Collation.Tailoring.get_tailoring("es", :standard)
iex> is_map(overlay)
true

parse_rules(rules_str)

@spec parse_rules(String.t()) :: [tuple()]

Parse a CLDR tailoring rule string into a list of operations.

Arguments

  • rules_str - a CLDR/ICU tailoring rule string.

Returns

A list of operation tuples:

  • {:reset, codepoints} — reset position to after the given character(s).
  • {:reset_before, level, codepoints} — reset to before at the given level.
  • {:primary, codepoints} — primary difference (<).
  • {:secondary, codepoints} — secondary difference (<<).
  • {:tertiary, codepoints} — tertiary difference (<<<).
  • {:option, key, value} — option override.

Examples

iex> ops = Cldr.Collation.Tailoring.parse_rules("&N<ñ<<<Ñ")
iex> length(ops)
3

supported_locales()

@spec supported_locales() :: [{String.t(), atom()}]

List all supported locale/type combinations.

Returns

A list of {language, type} tuples.

Examples

iex> locales = Cldr.Collation.Tailoring.supported_locales()
iex> {"es", :standard} in locales
true