pub struct LanguageEngine { /* private fields */ }Expand description
Language engine that loads the translation files for fluent for multiple languages and provides them as an API.
It uses the concurrent variant of the FluentBundle under the hood.
Implementations§
Source§impl LanguageEngine
impl LanguageEngine
Sourcepub fn new_empty() -> Self
pub fn new_empty() -> Self
Create a new language engine without any entries. It uses an empty LanguageManifest that only contains the language undefined (und).
Sourcepub fn load_from_directory(
path: impl AsRef<Path>,
) -> Result<Self, LanguageEngineLoaderError>
pub fn load_from_directory( path: impl AsRef<Path>, ) -> Result<Self, LanguageEngineLoaderError>
Loads translation data from the directory at path.
Expected layout:
{path}manifest.toml{language}.flt
The manifest.toml file has the same schema as LanguageManifest.
For each language defined in the manifest there must be a .flt file containing all messages needed for that language.
If a file is missing this will throw an error. Graceful degredation is not planned, if a language is missing it shouldn’t be in the manifest.
Sourcepub fn naive_get_text(
&self,
language: Option<UnicodeLanguageIdentifier>,
message_id: &str,
args: Option<&FluentArgs<'_>>,
) -> String
pub fn naive_get_text( &self, language: Option<UnicodeLanguageIdentifier>, message_id: &str, args: Option<&FluentArgs<'_>>, ) -> String
Naive implementation of a text getter that always returns a text.
When errors occur they are logged using the log crate.
A placeholder text is used in case a message can’t be reandered [NOT TRANSLATEABLE {id} {args}].
Sourcepub fn get_text_with_args(
&self,
language: Option<UnicodeLanguageIdentifier>,
message_id: &str,
args: impl IntoIterator<Item = (impl Into<String>, Variable)>,
) -> Result<String, TextFunctionError>
pub fn get_text_with_args( &self, language: Option<UnicodeLanguageIdentifier>, message_id: &str, args: impl IntoIterator<Item = (impl Into<String>, Variable)>, ) -> Result<String, TextFunctionError>
Returns the localized message for a given message id without passing any arguments to the message template.
Sourcepub fn get_text(
&self,
language: Option<UnicodeLanguageIdentifier>,
message_id: &str,
) -> Result<String, TextFunctionError>
pub fn get_text( &self, language: Option<UnicodeLanguageIdentifier>, message_id: &str, ) -> Result<String, TextFunctionError>
Returns the localized message for a given message id without passing any arguments to the message template.
Sourcepub fn get_text_with_raw_args(
&self,
language: Option<UnicodeLanguageIdentifier>,
message_id: &str,
args: Option<&FluentArgs<'_>>,
) -> Result<String, TextFunctionError>
pub fn get_text_with_raw_args( &self, language: Option<UnicodeLanguageIdentifier>, message_id: &str, args: Option<&FluentArgs<'_>>, ) -> Result<String, TextFunctionError>
Returns the translated text for a given language, message id and potential arguments
This will bypass argument checking from the language manifest file, use with care and document well.
Sourcepub fn language_manifest(&self) -> &LanguageManifest
pub fn language_manifest(&self) -> &LanguageManifest
Returns access to the underlying language manifest parsed from the languages/manifest.toml file.
Trait Implementations§
Source§impl Clone for LanguageEngine
impl Clone for LanguageEngine
Source§fn clone(&self) -> LanguageEngine
fn clone(&self) -> LanguageEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more