LiveSvelteGettext.Compiler (LiveSvelteGettext v0.2.0)
View SourceCompile-time code generation for LiveSvelteGettext.
This module is responsible for:
- Validating configuration options
- Scanning Svelte files and extracting translation strings
- Generating AST for gettext/ngettext calls (for extraction)
- Generating the runtime
all_translations/1function - Setting up
@external_resourcefor automatic recompilation
Summary
Functions
Generates the complete AST for the using module.
Validates the options passed to use LiveSvelteGettext.
Functions
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:
use Gettext, backend: <backend>for gettext integration@external_resourceattributes for each Svelte file- Module attribute with extracted translations for compile-time use
- Generated gettext/ngettext calls (for mix gettext.extract)
all_translations/1andtranslation_payload/1for runtime access__lsg_metadata__/0debug function
Examples
iex> ast = LiveSvelteGettext.Compiler.generate(
...> MyApp.Gettext,
...> MyApp.Gettext,
...> "test/fixtures/svelte"
...> )
iex> is_list(ast)
true
@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