LiveSvelteGettext.Compiler (LiveSvelteGettext v0.2.0)

View Source

Compile-time code generation for LiveSvelteGettext.

This module is responsible for:

  1. Validating configuration options
  2. Scanning Svelte files and extracting translation strings
  3. Generating AST for gettext/ngettext calls (for extraction)
  4. Generating the runtime all_translations/1 function
  5. Setting up @external_resource for automatic recompilation

Summary

Functions

Generates the complete AST for the using module.

Validates the options passed to use LiveSvelteGettext.

Functions

generate(caller_module, gettext_backend, svelte_path)

@spec generate(module(), module(), String.t()) :: Macro.t()

Generates the complete AST for the using module.

This is called at compile time and returns quoted expressions that will be injected into the caller's module.

What gets generated:

  1. use Gettext, backend: <backend> for gettext integration
  2. @external_resource attributes for each Svelte file
  3. Module attribute with extracted translations for compile-time use
  4. Generated gettext/ngettext calls (for mix gettext.extract)
  5. all_translations/1 and translation_payload/1 for runtime access
  6. __lsg_metadata__/0 debug function

Examples

iex> ast = LiveSvelteGettext.Compiler.generate(
...>   MyApp.Gettext,
...>   MyApp.Gettext,
...>   "test/fixtures/svelte"
...> )
iex> is_list(ast)
true

validate_options!(opts)

@spec validate_options!(keyword()) :: :ok

Validates the options passed to use LiveSvelteGettext.

Raises a ArgumentError if options are invalid.

Examples

iex> LiveSvelteGettext.Compiler.validate_options!(
...>   gettext_backend: MyApp.Gettext,
...>   svelte_path: "assets/svelte"
...> )
:ok

iex> LiveSvelteGettext.Compiler.validate_options!([])
** (ArgumentError) :gettext_backend is required