Struct perseus::Translator [−][src]
pub struct Translator { /* fields omitted */ }
Expand description
Manages translations on the client-side for a single locale using Mozilla’s Fluent syntax. This
should generally be placed into an Rc<T>
and referred to by every template in an app. You do NOT want to be cloning potentially
thousands of translations!
Fluent supports compound messages, with many variants, which can specified here using the form [id].[variant]
in a translation ID,
as a .
is not valid in an ID anyway, and so can be used as a delimiter. More than one dot will result in an error.
Implementations
Creates a new translator for a given locale, passing in translations in FTL syntax form.
Gets the path to the given URL in whatever locale the instance is configured for. This also applies the path prefix.
Gets the locale for which this instancce is configured.
Translates the given ID. This additionally takes any arguments that should be interpolated. If your i18n system also has variants, they should be specified somehow in the ID.
Panics
This will panic!
if any errors occur while trying to prepare the given ID. Therefore, this method should only be used for
hardcoded IDs that can be confirmed as valid. If you need to parse arbitrary IDs, use .translate_checked()
instead.
pub fn translate_checked<I: Into<String> + Display>(
&self,
id: I,
args: Option<FluentArgs<'_>>
) -> Result<String, TranslatorError>
pub fn translate_checked<I: Into<String> + Display>(
&self,
id: I,
args: Option<FluentArgs<'_>>
) -> Result<String, TranslatorError>
Translates the given ID, returning graceful errors. This additionally takes any arguments that should be interpolated. If your i18n system also has variants, they should be specified somehow in the ID.
Gets the Fluent bundle for more advanced translation requirements.