pub struct FluentCatalog { /* private fields */ }Expand description
Fluent catalog keyed by gatekeep reason codes.
Implementations§
Source§impl FluentCatalog
impl FluentCatalog
Sourcepub fn set_fallback_locale(
&mut self,
locale: impl AsRef<str>,
) -> Result<(), FluentCatalogError>
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.
Sourcepub fn with_fallback_locale(
self,
locale: impl AsRef<str>,
) -> Result<Self, FluentCatalogError>
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.
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.
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.
Sourcepub fn add_resource(
&mut self,
locale: impl AsRef<str>,
source: impl Into<String>,
) -> Result<(), FluentCatalogError>
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.
Sourcepub fn with_resource(
self,
locale: impl AsRef<str>,
source: impl Into<String>,
) -> Result<Self, FluentCatalogError>
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.
Sourcepub fn render_reason(&self, reason: &DenialReason, locale: &Locale) -> String
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.
Sourcepub fn try_render_reason(
&self,
reason: &DenialReason,
locale: &Locale,
) -> Option<String>
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.