Search documentation of Localize

# Localize.Collation.Tailoring (Localize v0.39.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_tailoring(language, type)

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

parse_rules(rules_str)

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

supported_locales()

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.

### 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 overlay entries and a keyword list of option overrides.

- `nil` - if no tailoring exists for the given locale and type.

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

### Examples

    iex> ops = Localize.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 = Localize.Collation.Tailoring.supported_locales()
    iex> {"es", :standard} in locales
    true