AshGettext.Extractor (AshGettext v0.1.0)

Copy Markdown View Source

Shows every text AshGettext translates to mix gettext.extract.

mix gettext.extract compiles the app and records each Gettext macro it meets. The texts AshGettext translates are plain strings, not macro calls: enum labels, attribute labels, message: options and the sentences for Ash's own errors. So while the app compiles, AshGettext.Enum and AshGettext.Domain hand each one to Gettext.Macros.dgettext_noop_with_backend/3 in the app's own modules, with the backend and text domain the lookups use.

A validation or change module a resource uses is read from its source file: every message: whose value is a plain string is found there. An interpolated message (message: "too heavy: #{weight}") cannot be a msgid, so it is reported as a compile warning instead.

Summary

Functions

Scan sources — a list of {path, contents} — for translatable messages.

Marks each text for mix gettext.extract, as if env's module had called Gettext.Macros.dgettext_noop_with_backend(backend, text_domain, text). Does nothing unless Gettext is extracting.

The texts a resource shows: its written attribute labels and, with messages?, every literal message in its DSL and in the app's own validation, change and preparation modules it uses.

Types

find_result()

@type find_result() :: %{messages: [message()], interpolated: [interpolated()]}

interpolated()

@type interpolated() :: %{path: String.t(), line: pos_integer()}

message()

@type message() :: %{msgid: String.t(), references: [reference_entry()]}

reference_entry()

@type reference_entry() :: %{path: String.t(), line: pos_integer()}

Functions

find_messages(sources)

@spec find_messages([{String.t(), String.t()}]) :: find_result()

Scan sources — a list of {path, contents} — for translatable messages.

Returns the extractable msgids with every place they appear, and separately the interpolated messages that cannot become msgids as written.

mark(env, backend, text_domain, texts)

@spec mark(Macro.Env.t(), module(), String.t(), [String.t()]) :: :ok

Marks each text for mix gettext.extract, as if env's module had called Gettext.Macros.dgettext_noop_with_backend(backend, text_domain, text). Does nothing unless Gettext is extracting.

resource_texts(resource, messages?)

@spec resource_texts(module(), boolean()) :: [String.t()]

The texts a resource shows: its written attribute labels and, with messages?, every literal message in its DSL and in the app's own validation, change and preparation modules it uses.