Skip to main content

FluentZeroBuilder

Struct FluentZeroBuilder 

Source
pub struct FluentZeroBuilder { /* private fields */ }
Expand description

A builder to configure and generate the static cache code for fluent-zero.

Implementations§

Source§

impl FluentZeroBuilder

Source

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.
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for FluentZeroBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FluentZeroBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FluentZeroBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.