Idiom.Cache (idiom v0.1.0)

Cache for translations.

Idiom is flexible in terms of which source translations can be retrieved from. It comes with a few different ones out of the box, and can also be extended through plugins. Idiom.Cache provides utilities to interact with the ETS table that acts as a central storage for translations, both for adding/updating keys and retrieving values.

Summary

Functions

Link to this function

get_translation(language, namespace, key, table_name \\ :idiom_cache)

@spec get_translation(String.t(), String.t(), String.t(), atom()) :: String.t() | nil

Retrieves a translation from the cache.

Examples

iex> Cache.get_translation("de", "default", "butterfly")
"Schmetterling"
Link to this function

init(initial_state \\ %{}, table_name \\ :idiom_cache)

@spec init(map(), atom()) :: :ok

Starts a new cache.

Allows adding initial state by passing it as first parameter.

Examples

iex> initial_state = %{
...>  "en" => %{"signup" => %{"Create your account" => "Create your account"}}, 
...>  "de" => %{"signup" => %{"Create your account" => "Erstelle deinen Account"}}
...>}
iex> Idiom.Cache.init(initial_state)
:ok

iex> Idiom.Cache.init(%{}, :different_cache_name)
:ok
Link to this function

insert_keys(keys, table_name \\ :idiom_cache)

Adds a map of keys to the cache.

Examples

iex> Idiom.Cache.insert_keys(%{
...>  "en" => %{"signup" => %{"Create your account" => "Create your account"}}, 
...>  "de" => %{"signup" => %{"Create your account" => "Erstelle deinen Account"}}}
...>)
:ok