Skip to main content

generate_static_cache

Function generate_static_cache 

Source
pub fn generate_static_cache(locales_dir_path: &str)
Expand description

Generates the static cache code for fluent-zero.

This function reads Fluent (.ftl) files from the specified directory, parses them, and generates a Rust file (static_cache.rs) in the OUT_DIR.

§Process

  1. Scans locales_dir_path for language subdirectories (e.g., en-US).
  2. Parses every .ftl file found.
  3. Identifies Static messages (no variables, standard text) vs Dynamic messages.
  4. Generates:
    • CACHE: A Perfect Hash Map (PHF) mapping keys to CacheEntry::Static(&str) or CacheEntry::Dynamic.
    • LOCALES: A Map of Lazy-loaded ConcurrentFluentBundles for fallback/dynamic resolution.

§Arguments

  • locales_dir_path - Relative path to the folder containing locale subdirectories.