pub struct FluentZeroBuilder { /* private fields */ }Expand description
A builder to configure and generate the static cache code for fluent-zero.
Implementations§
Source§impl FluentZeroBuilder
impl FluentZeroBuilder
Sourcepub fn new<P: AsRef<Path>>(locales_dir_path: P) -> Self
pub fn new<P: AsRef<Path>>(locales_dir_path: P) -> Self
Creates a new builder pointing to the directory containing locale subdirectories.
§Arguments
locales_dir_path- Relative path to the folder containing locale subdirectories.
Sourcepub fn crate_path(self, path: impl Into<String>) -> Self
pub fn crate_path(self, path: impl Into<String>) -> Self
Sets the path the generated code uses to reach the fluent-zero crate.
Defaults to ::fluent_zero. Set it when the dependency is renamed in
Cargo.toml, e.g. fz = { package = "fluent-zero", ... } needs
.crate_path("::fz"). An invalid path makes
try_generate return Error::InvalidCratePath.
Sourcepub fn missing_translations(self, level: MissingTranslations) -> Self
pub fn missing_translations(self, level: MissingTranslations) -> Self
Sets how messages present in the fallback locale (see
fallback_locale, en-US by default) but
missing from another locale are reported. Defaults to
MissingTranslations::Warn.
Sourcepub fn export_charset<P: AsRef<Path>>(self, dest: P) -> Self
pub fn export_charset<P: AsRef<Path>>(self, dest: P) -> Self
Opt-in to exporting a deterministic text file containing all unique
characters used across all .ftl files in this crate and its dependencies.
Dependency Aggregation: This natively aggregates characters from dependencies using Cargo’s standard IPC. No metadata scraping or tree walking is required.
dest should live inside OUT_DIR (e.g. Path::new(&out_dir).join("chars.txt"))
so the build stays hermetic. A relative path is resolved against the
build script’s working directory (the package root); one that lands
outside OUT_DIR still works, but emits a cargo:warning.
Sourcepub fn fallback_locale(self, locale: &str) -> Self
pub fn fallback_locale(self, locale: &str) -> Self
Sets the locale lookups fall back to when neither the active language
nor its fallback chain has a message. Defaults to en-US.
The generated code exports it as FALLBACK and the t! macros use it.
It is also the locale the missing translations
report compares every other locale against, and the one whose source
documents the generated keys constants.
When the locales directory holds any locale,
try_generate returns
Error::MissingFallbackLocale unless one of them is this locale, so a
typo cannot silently disable the fallback; a locale that does not parse
is Error::InvalidFallbackLocale.
Sourcepub fn use_isolating(self, use_isolating: bool) -> Self
pub fn use_isolating(self, use_isolating: bool) -> Self
Whether placeables are wrapped in the Unicode bidi isolation marks
U+2068 / U+2069 (default true, matching fluent-bundle).
The marks keep right-to-left arguments from scrambling surrounding
left-to-right text (and vice versa), but many GUI font stacks render
them as boxes or odd gaps. The setting applies to the generated runtime
bundles and to static messages formatted at build time alike, so both
stay byte-identical. While enabled, the marks are added to CHARSET
whenever some message can emit them.
Sourcepub fn generate(self)
pub fn generate(self)
Consumes the builder, parses the Fluent files, aggregates IPC variables, and generates the Rust static cache code.
This is the panicking convenience over try_generate,
meant for build scripts where a panic is the natural way to fail.
§Panics
Panics with the error’s message (prefixed with fluent-zero-build: )
whenever try_generate returns an error.
Sourcepub fn try_generate(self) -> Result<(), Error>
pub fn try_generate(self) -> Result<(), Error>
Consumes the builder, parses the Fluent files, aggregates IPC variables, and generates the Rust static cache code.
§Errors
Returns an Error if OUT_DIR is not set, the
crate_path is invalid, the
fallback_locale is invalid or has no
directory, an .ftl file fails to parse, an ID is defined twice in one
locale, translations are missing under MissingTranslations::Deny,
or reading the locales or writing the output fails.