Localize.Locale.Provider.PersistentTerm (Localize v0.5.0)

Copy Markdown View Source

A locale data provider that stores locale data in :persistent_term.

This provider loads CLDR locale data from .etf files in the priv/localize/locales/ directory and caches it in :persistent_term for fast, concurrent access without copying.

Summary

Functions

Retrieves a value from locale data stored in :persistent_term.

Loads locale data for the given locale.

Returns whether locale data has been loaded into :persistent_term.

Stores locale data in :persistent_term.

Functions

get(locale, keys, options \\ [])

Retrieves a value from locale data stored in :persistent_term.

Navigates the locale data map using the provided list of keys. When the :fallback option is true and the key path is not found, parent locales are searched according to the CLDR locale inheritance chain.

Arguments

  • locale is a locale identifier atom or a Localize.LanguageTag.t/0.

  • keys is a list of keys to traverse in the locale data map.

  • options is a keyword list of options. The default is [].

Options

  • :fallback is a boolean. When true, parent locales are searched if the key path is not found in the requested locale. The default is false.

Returns

  • {:ok, value} if the key path resolves to a value.

  • {:error, reason} if the key path cannot be resolved.

load(locale)

Loads locale data for the given locale.

Locale data is resolved in the following order:

  1. If a fresh copy is present in the on-disk cache (see Localize.Locale.Provider.Cache), it is returned.

  2. In :dev and :test environments, the locale is generated from the CLDR source data via Localize.Data.Locale.generate_and_transform/1.

  3. Otherwise, the locale is downloaded via Localize.Locale.Provider.download_locale/1, written to the cache, decoded, and returned.

Arguments

Returns

  • {:ok, locale_data} where locale_data is a map of the locale's CLDR data.

  • {:error, exception} if the locale data cannot be obtained.

loaded?(locale)

Returns whether locale data has been loaded into :persistent_term.

Arguments

Returns

  • true if the locale data is stored in :persistent_term.

  • false otherwise.

store(locale_id, locale_data)

Stores locale data in :persistent_term.

Arguments

  • locale_id is a locale identifier atom.

  • locale_data is a map of locale data to store.

Returns

  • :ok on success.

  • {:error, reason} on failure.