[−][src]Struct fluent_ergonomics::FluentErgo
Implementations
impl FluentErgo
[src]
An Ergonomic class wrapping the Fluent library
pub fn new(languages: &[LanguageIdentifier]) -> FluentErgo
[src]
Construct the class with a list of languages. The list must be sorted in the order that language packs will be tested. The first language listed will be the first language searched for any translation message.
Typically, I call this as
let eo_id = "eo".parse::<unic_langid::LanguageIdentifier>().unwrap(); let en_id = "en-US".parse::<unic_langid::LanguageIdentifier>().unwrap(); let mut fluent = fluent_ergonomics::FluentErgo::new(&[eo_id, en_id]);
This specifies that I want to first look up messages in the Esperanto list, then fall back to the English specfications if no Esperanto specification is present.
Note that no language resources are loaded during construction. You must call
add_from_text
or add_from_file
to load language packs.
pub fn add_from_text(
&mut self,
lang: LanguageIdentifier,
text: String
) -> Result<(), Error>
[src]
&mut self,
lang: LanguageIdentifier,
text: String
) -> Result<(), Error>
Add a list of translation strings from a string, which can be a constant hard-coded in the
application, loaded from a file, loaded from the internet, or wherever you like. lang
specifies which language the translation strings being provided.
You should not specify a language that you did not include in the constructor. You can, but the translation function will only check those languages specified when this object was constructed.
Errors
FluentError
FluentParserError
pub fn add_from_file(
&mut self,
lang: LanguageIdentifier,
path: &Path
) -> Result<(), Error>
[src]
&mut self,
lang: LanguageIdentifier,
path: &Path
) -> Result<(), Error>
Like add_from_text
, but this will load the translation strings from a file.
Note that this will load the entire file into memory before passing it to Fluent. While I think it is unlikely, it is possible that a translation file may be so big as to run the computer out of memory.
Errors
FluentError
FluentParserError
FileEncodingError
-- all files must be encoded in UTF-8. Most files saved from text editors already do proper UTF-8 encoding, so this should rarely be a problem.
pub fn tr(
&self,
msgid: &str,
args: Option<&FluentArgs>
) -> Result<String, Error>
[src]
&self,
msgid: &str,
args: Option<&FluentArgs>
) -> Result<String, Error>
Run a translation.
msgid
is the translation identifier as specified in the translation strings. args
is a
set of Fluent arguments to be interpolated into the strings.
This function will search language bundles in the order that they were specified in the constructor. NoMatchingMessage will be returned only if the message identifier cannot be found in any bundle.
length-without-label = {$value} swimming = Swimming units = Units
With this set of translation strings, length-without-label
, swimming
, and units
are
all valid translation identifiers. See the documentation for FluentBundle.get_message
for
more information.
A typical call with arguments would look like this:
use fluent::{FluentArgs, FluentValue}; let eo_id = "eo".parse::<unic_langid::LanguageIdentifier>().unwrap(); let en_id = "en-US".parse::<unic_langid::LanguageIdentifier>().unwrap(); let mut fluent = fluent_ergonomics::FluentErgo::new(&[eo_id, en_id]); let mut args = FluentArgs::new(); args.insert("value", FluentValue::from("15")); let r = fluent.tr("length-without-label", Some(&args));
Errors
- NoMatchingMessage -- this will be returned if the message identifier cannot be found in any language bundle.
Trait Implementations
impl Clone for FluentErgo
[src]
fn clone(&self) -> FluentErgo
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for FluentErgo
[src]
impl Default for FluentErgo
[src]
fn default() -> FluentErgo
[src]
Auto Trait Implementations
impl RefUnwindSafe for FluentErgo
impl Send for FluentErgo
impl Sync for FluentErgo
impl Unpin for FluentErgo
impl UnwindSafe for FluentErgo
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,