Search documentation of Localize

# Localize.Collation.Tailoring.LocaleDefaults (Localize v0.39.0)

Copy Markdown View Source

Preset collation option defaults for common locales.

Maps BCP47 language tags to their standard collation option overrides as defined by CLDR. These defaults are applied before any explicit BCP47 `-u-` extension keys.

## Summary

### Functions

default_type(locale)

Get the default collation type for a locale.

extract_language(locale)

Extract the language subtag from a BCP47 locale string.

options_for(locale)

Get option overrides for a locale.

## Functions

# default_type(locale)

    @spec default_type(String.t()) :: atom()

Get the default collation type for a locale.

### Arguments

- `locale` - a BCP47 locale string.

### Returns

The default collation type atom for the locale, or `:standard`.

### Examples

    iex> Localize.Collation.Tailoring.LocaleDefaults.default_type("de")
    :standard

    iex> Localize.Collation.Tailoring.LocaleDefaults.default_type("es")
    :standard

# extract_language(locale)

    @spec extract_language(String.t()) :: String.t()

Extract the language subtag from a BCP47 locale string.

### Arguments

- `locale` - a BCP47 locale string.

### Returns

The lowercase language subtag string.

### Examples

    iex> Localize.Collation.Tailoring.LocaleDefaults.extract_language("de-AT-u-co-phonebk")
    "de"

    iex> Localize.Collation.Tailoring.LocaleDefaults.extract_language("sv")
    "sv"

# options_for(locale)

    @spec options_for(String.t()) :: keyword()

Get option overrides for a locale.

### Arguments

- `locale` - a BCP47 locale string (e.g., `"da"`, `"de-AT"`, `"sv-SE"`).

### Returns

A keyword list of option overrides, or an empty list if no defaults exist.

### Examples

    iex> Localize.Collation.Tailoring.LocaleDefaults.options_for("da")
    [case_first: :upper]

    iex> Localize.Collation.Tailoring.LocaleDefaults.options_for("en")
    []