VerifiedTranslations.Message (verified_translations v0.1.1)

Copy Markdown View Source

One translation file: <path>/<domain>/<slug>-<hash>.json holding the source text ("msgid") and one key per locale.

The file name is derived from the source text, so finding a message never requires an index and two branches adding different messages never touch the same file.

Summary

Functions

Placeholder names (%{name}) used in text.

Atomically creates path with content unless it exists. Returns true if written. Parallel compilers never see a partially written file.

Encodes a message deterministically: msgid first, then locales sorted.

File name for msgid: readable slug plus a content hash of identity.

Path of the JSON file for msgid.

Reads a message file.

Plural source forms in CLDR order, as path/4 expects for tn/2 messages.

Merges translations into the file for msgid, creating it if missing. Raises if the existing file is invalid or belongs to another msgid.

Functions

bindings(text)

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

Placeholder names (%{name}) used in text.

create(path, content)

@spec create(Path.t(), String.t()) :: boolean()

Atomically creates path with content unless it exists. Returns true if written. Parallel compilers never see a partially written file.

encode(msgid, translations, opts \\ [])

Encodes a message deterministically: msgid first, then locales sorted.

file_name(identity, msgid \\ nil)

@spec file_name(String.t(), String.t()) :: String.t()

File name for msgid: readable slug plus a content hash of identity.

path(root, domain, msgid, opts \\ [])

@spec path(Path.t(), String.t(), String.t(), keyword()) :: Path.t()

Path of the JSON file for msgid.

Options

  • :context - Gettext-style message context (msgctxt)
  • :plural - true for ~t"..."N, or the source forms map of tn/2

read(path)

@spec read(Path.t()) :: {:ok, map(), binary()} | {:error, :enoent | String.t()}

Reads a message file.

sorted_forms(forms)

@spec sorted_forms(%{required(String.t()) => String.t()}) :: [
  {String.t(), String.t()}
]

Plural source forms in CLDR order, as path/4 expects for tn/2 messages.

update!(path, msgid, translations, origin \\ nil)

@spec update!(Path.t(), String.t(), map(), map() | nil) :: :ok

Merges translations into the file for msgid, creating it if missing. Raises if the existing file is invalid or belongs to another msgid.

origin (e.g. %{"by" => "machine", "model" => "claude-opus-5-5"}, or nil for human-written) is recorded for every locale in translations.