Search documentation of Localize

# Localize.Collation.Reorder (Localize v0.39.0)

Copy Markdown View Source

Script reordering for collation (kr= / reorder option).

Remaps primary weights to change the relative order of scripts. For example, `reorder: [:Grek, :Latn]` would sort Greek characters before Latin characters.

## Summary

### Functions

apply_mapping(mapping_fn, primary)

Apply a reorder mapping to a primary weight.

build_mapping(reorder_codes)

Build a reorder mapping function from the given script codes.

load_primary_to_fractional_lead()

Load a mapping from allkeys integer primary weights to their fractional lead bytes and sub-bytes.

load_script_ranges()

Load the script-to-lead-byte-range mapping from FractionalUCA.txt.

## Functions

# apply_mapping(mapping_fn, primary)

    @spec apply_mapping((non_neg_integer() -> non_neg_integer()) | nil, non_neg_integer()) ::
      non_neg_integer()

Apply a reorder mapping to a primary weight.

### Arguments

- `mapping_fn` - a reorder mapping function from `build_mapping/1`, or `nil`.

- `primary` - the primary weight to remap.

### Returns

The remapped primary weight, or the original if `mapping_fn` is `nil`.

# build_mapping(reorder_codes)

    @spec build_mapping([atom()]) :: (non_neg_integer() -> non_neg_integer()) | nil

Build a reorder mapping function from the given script codes.

### Arguments

- `reorder_codes` - a list of script code atoms (e.g., `[:Grek, :Latn]`).

### Returns

- A function `(primary :: integer()) -> integer()` that remaps primary weights.

- `nil` if the list is empty or no valid mappings were found.

# load_primary_to_fractional_lead()

    @spec load_primary_to_fractional_lead() :: %{
      required(integer() | {:sub, integer()}) => non_neg_integer()
    }

Load a mapping from allkeys integer primary weights to their fractional lead bytes and sub-bytes.

### Returns

A map `%{integer() | {:sub, integer()} => non_neg_integer()}`.

# load_script_ranges()

    @spec load_script_ranges() :: %{
      required(String.t()) => {non_neg_integer(), non_neg_integer()}
    }

Load the script-to-lead-byte-range mapping from FractionalUCA.txt.

### Returns

A map `%{String.t() => {start_byte, end_byte}}`.