Localize.Inflection.Provider (Localize v1.4.0)

Copy Markdown View Source

Downloads inflection data files from the Localize CDN.

Inflection data is optional and versioned independently of both the Localize package and the CLDR data: its version is the pinned unicode-org/inflection commit (abbreviated) plus a pipeline revision, so the data only re-publishes when the upstream pin or the generation pipeline changes.

Files live at <base-url>/<data-version>/<file> — one <locale>.etf per locale, each carrying that locale's lexicon, metadata, and pronoun table. Downloads are verified against the SHA-256 manifest shipped in the package (priv/localize/inflection_hashes.etf) before anything is written, mirroring the locale-file integrity scheme (see Localize.Locale.Provider).

Summary

Functions

Returns the CDN base URL for inflection data.

Returns the inflection data version.

Downloads a data file and verifies it against the packaged SHA-256 manifest.

Returns the download URL for a data file of the current data version.

Returns the full pinned unicode-org/inflection commit SHA.

Functions

base_url()

Returns the CDN base URL for inflection data.

Overridable for mirrors:

config :localize, inflection_base_url: "https://mirror.example.com/inflection"

Returns

  • The configured :inflection_base_url, or the Localize CDN's.

Examples

iex> Localize.Inflection.Provider.base_url()
"https://elixir-localize.com/inflection"

data_version()

Returns the inflection data version.

Returns

  • The first 12 characters of the pinned upstream commit and the data revision, joined by -r.

Examples

iex> Localize.Inflection.Provider.data_version()
"ae92d425e57a-r3"

download_file(file_name)

Downloads a data file and verifies it against the packaged SHA-256 manifest.

Arguments

  • file_name is a file name such as "ru.etf".

Returns

  • {:ok, binary} with the verified contents, or {:error, exception}.

Examples

A string name is downloaded, so the example shows the one answer that needs no network, for a name that is not a string:

iex> Localize.Inflection.Provider.download_file(:ru) |> elem(0)
:error

file_url(file_name)

Returns the download URL for a data file of the current data version.

Arguments

  • file_name is a file name such as "ru.etf".

Returns

Examples

iex> Localize.Inflection.Provider.file_url("ru.etf")
"https://elixir-localize.com/inflection/ae92d425e57a-r3/ru.etf"

upstream_sha()

Returns the full pinned unicode-org/inflection commit SHA.

Returns

  • The 40-character commit SHA, whose first 12 characters begin the data version.

Examples

iex> sha = Localize.Inflection.Provider.upstream_sha()
iex> String.starts_with?(Localize.Inflection.Provider.data_version(), binary_part(sha, 0, 12))
true