Skip to main content

FluentCatalog

Struct FluentCatalog 

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

Fluent catalog keyed by gatekeep reason codes.

Implementations§

Source§

impl FluentCatalog

Source

pub fn new() -> Self

Creates an empty catalog.

Source

pub fn set_fallback_locale( &mut self, locale: impl AsRef<str>, ) -> Result<(), FluentCatalogError>

Sets the locale to try after the requested locale cannot render.

§Errors

Returns FluentCatalogError::InvalidLocale when locale is not a well-formed Unicode language identifier.

Source

pub fn with_fallback_locale( self, locale: impl AsRef<str>, ) -> Result<Self, FluentCatalogError>

Returns this catalog with a fallback locale configured.

§Errors

Returns FluentCatalogError::InvalidLocale when locale is not a well-formed Unicode language identifier.

Source

pub fn set_hidden_message( &mut self, message_id: impl Into<String>, fallback: impl Into<String>, ) -> Result<(), FluentCatalogError>

Sets the generic message used for hidden denials.

Hidden denials must not render their specific reason code because that can disclose the protected resource’s existence. The catalog looks up message_id in the requested locale and then the fallback locale; if no message exists, it returns fallback.

§Errors

Returns FluentCatalogError::EmptyMessageId when message_id is blank or FluentCatalogError::EmptyFallbackMessage when fallback is blank.

Source

pub fn with_hidden_message( self, message_id: impl Into<String>, fallback: impl Into<String>, ) -> Result<Self, FluentCatalogError>

Returns this catalog with a generic hidden-denial message configured.

§Errors

Returns FluentCatalogError::EmptyMessageId when message_id is blank or FluentCatalogError::EmptyFallbackMessage when fallback is blank.

Source

pub fn add_resource( &mut self, locale: impl AsRef<str>, source: impl Into<String>, ) -> Result<(), FluentCatalogError>

Adds an FTL resource to the bundle for locale.

Multiple resources may be added to one locale. Fluent duplicate-message errors are reported instead of overriding an earlier message.

§Errors

Returns FluentCatalogError when the locale is invalid, the FTL source has parse errors, or Fluent rejects the resource for that locale.

Source

pub fn with_resource( self, locale: impl AsRef<str>, source: impl Into<String>, ) -> Result<Self, FluentCatalogError>

Returns this catalog with an FTL resource added.

§Errors

Returns FluentCatalogError when the resource cannot be added.

Source

pub fn render_reason(&self, reason: &DenialReason, locale: &Locale) -> String

Renders reason, falling back to the stable reason code for forbidden denials or to the generic hidden message for hidden denials.

Source

pub fn try_render_reason( &self, reason: &DenialReason, locale: &Locale, ) -> Option<String>

Renders reason only when a matching Fluent message exists and resolves without runtime formatting errors.

Hidden denials use the configured generic hidden message id instead of reason.code.

Trait Implementations§

Source§

impl Default for FluentCatalog

Source§

fn default() -> Self

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

impl ReasonCatalog for FluentCatalog

Source§

fn render(&self, reason: &DenialReason, locale: &Locale) -> String

Renders a denial reason for the requested locale.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.