pub struct TranslatableString(pub BTreeMap<String, String>);Expand description
A wrapper around a translatable string.
§Example
use appstream::TranslatableString;
let name = TranslatableString::with_default("Contrast")
.and_locale("cs", "Kontrast")
.and_locale("cs", "Kontrast");Tuple Fields§
§0: BTreeMap<String, String>Implementations§
Source§impl TranslatableString
impl TranslatableString
Sourcepub fn with_default(text: &str) -> Self
pub fn with_default(text: &str) -> Self
Create a new TranslatableString using the default locale.
§Arguments
text- The string that corresponds to the default locale.
Sourcepub fn and_locale(self, locale: &str, text: &str) -> Self
pub fn and_locale(self, locale: &str, text: &str) -> Self
Adds a new translation for a specific locale.
Very useful when constructing a TranslatableString manually.
§Arguments
locale- The locale to use, usewith_defaultif you want the default locale.text- The corresponding translation.
Sourcepub fn add_for_element(&mut self, element: &Element)
pub fn add_for_element(&mut self, element: &Element)
Adds a new string from a xmltree.Element
XML elements containing a lang attribute are marked as translatable
and can be used to feed the TranslatableString.
Sourcepub fn add_for_locale(&mut self, locale: Option<&str>, text: &str)
pub fn add_for_locale(&mut self, locale: Option<&str>, text: &str)
Adds a new translation for a speicifc locale.
§Arguments
locale- The locale to use, the default locale is used ifNoneis set instead.text- The translation corresponding to the locale.
Sourcepub fn get_default(&self) -> Option<&String>
pub fn get_default(&self) -> Option<&String>
Returns the text corresponding to the default locale C.
Trait Implementations§
Source§impl Clone for TranslatableString
impl Clone for TranslatableString
Source§fn clone(&self) -> TranslatableString
fn clone(&self) -> TranslatableString
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TranslatableString
impl Debug for TranslatableString
Source§impl Default for TranslatableString
impl Default for TranslatableString
Source§fn default() -> TranslatableString
fn default() -> TranslatableString
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for TranslatableString
impl<'de> Deserialize<'de> for TranslatableString
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for TranslatableString
impl PartialEq for TranslatableString
Source§impl Serialize for TranslatableString
impl Serialize for TranslatableString
impl StructuralPartialEq for TranslatableString
Auto Trait Implementations§
impl Freeze for TranslatableString
impl RefUnwindSafe for TranslatableString
impl Send for TranslatableString
impl Sync for TranslatableString
impl Unpin for TranslatableString
impl UnwindSafe for TranslatableString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more