MishkaCmsCore.Runtime.States.TranslationsState (Mishka CMS Core v0.0.1)

Copy Markdown View Source

ETS copy of MishkaCmsCore.Runtime.Translation, so t/1 is answered without a query.

The same shape as MishkaCmsCore.Runtime.States.SettingsState, for the same reasons: loaded once at boot, then kept current off the resource's own PubSub broadcasts, which reach every node — a translation saved on one server is on all of them without a restart.

Each entry is {{site_id, language, key}, value}, site_id nil for a global row. Only rows that HAVE a value are kept: a registered key nobody has translated is the same to t/1 as no row at all, and it would only cost memory.

Summary

Functions

Returns a specification to start this module under a supervisor.

Every language a cached translation is written in.

The value for key in language on site_id, falling back to the global row, else nil.

Put one translation in the cache directly (test and seed helper).

Reload every translation from the database.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

languages()

@spec languages() :: [String.t()]

Every language a cached translation is written in.

lookup(site_id, language, key)

@spec lookup(String.t() | nil, String.t(), String.t()) :: String.t() | nil

The value for key in language on site_id, falling back to the global row, else nil.

Two lookups at most, no GenServer hop. Never raises: a table that is not there yet is the same as one with nothing in it, so a template rendered before this process starts shows its keys.

put(site_id, language, key, value)

@spec put(String.t() | nil, String.t(), String.t(), String.t() | nil) :: :ok

Put one translation in the cache directly (test and seed helper).

refresh()

@spec refresh() :: :ok

Reload every translation from the database.

start_link(opts \\ [])