rebar3_erli18n_prv_compile (rebar3_erli18n v0.2.0)

Copy Markdown View Source

rebar3 erli18n compile — opt-in compile-time .po->BEAM catalog codegen.

For every (Domain, Locale) catalog under the catalog root this provider reads the .po, parses its entries and compiles its Plural-Forms rule AHEAD of time, then emits a tiny generated carrier module (erli18n_cc_<Domain>__<Locale>.erl) whose catalog/0 returns the ALREADY-parsed entries plus the ALREADY-compiled plural rule baked into the BEAM literal pool (see rebar3_erli18n_codegen). A consumer registers them at boot through erli18n:register_compiled_catalogs/1 with NO runtime .po parse and NO plural compile.

The whole surface is OPT-IN: with no {compiled_catalogs, true} in rebar.config the provider is a loud-logged no-op and writes nothing, so a project that uses no compiled catalogs sees zero change. Reading the runtime ensure_loaded/3 path stays the default.

Configuration (read from rebar.config)

The entire surface is read via rebar3_erli18n_host:get_config/3 under the erli18n key:

  • compiled_catalogs — master gate; false/absent makes the provider a loud-logged no-op.
  • key_checkoff | warn | strict; an unknown atom normalises to warn (logged once). Folds in the compiled-catalog key-existence check after codegen.

  • compiled_domainsall (default: every extracted domain that has a catalog) or an explicit [atom()] list; scopes BOTH the codegen and the key check.
  • gen_dir — output directory for the generated carriers (default "src/erli18n_gen", resolved relative to the root app).
  • include_fuzzy — include #, fuzzy entries (default false), passed to erli18n_po:parse/2 and baked into header.fuzzy_included.
  • gen_eqwalizer_nowarn — emit the function-scoped eqwalizer nowarn on each carrier's catalog/0 (default true), passed as render options.
  • max_po_bytes — reject a .po larger than this many bytes BEFORE reading it (default: the runtime library's erli18n_server:default_max_bytes/0, 16 MiB); infinity disables the size cap.
  • max_entries — reject a parsed catalog with more than this many entries (default: the runtime library's erli18n_server:default_max_entries/0, 500000); infinity disables the entry cap. Both caps mirror the runtime loader so a compiled carrier can never carry more than ensure_loaded/3 would accept; a violation is a loud build error.

Command-line options

--strict (treat missing keys as a build failure), --no-key-check (skip the key check entirely), --check (dry run: generate nothing, only validate) plus the shared --domain and --pot-dir. Policy precedence: --no-key-check > --strict/--check > the {key_check} config > the default warn.

Summary

Functions

Run the compile provider.

Render a provider error to a human-readable string.

Register the compile provider under the erli18n namespace.

Functions

do(State)

-spec do(rebar3_erli18n_host:state()) -> {ok, rebar3_erli18n_host:state()} | {error, string()}.

Run the compile provider.

A loud-logged no-op (writing nothing) unless {compiled_catalogs, true} is in rebar.config. Otherwise generates one carrier per (Domain, Locale) and runs the folded key check.

format_error/1

-spec format_error(term()) -> string().

Render a provider error to a human-readable string.

init(State)

Register the compile provider under the erli18n namespace.