pub struct CompiledCatalog {
pub locale: String,
/* private fields */
}Expand description
A compiled catalog with lookup and formatting.
Fields§
§locale: StringLocale associated with the compiled catalog.
Implementations§
Source§impl CompiledCatalog
impl CompiledCatalog
Sourcepub fn get(&self, key: &str) -> Option<&CompiledMessage>
pub fn get(&self, key: &str) -> Option<&CompiledMessage>
Get a compiled message by key.
Sourcepub fn format(&self, key: &str, values: &MessageValues) -> String
pub fn format(&self, key: &str, values: &MessageValues) -> String
Format a message by key, returning the key itself if missing.
Examples found in repository?
examples/catalog_runtime.rs (line 20)
6fn main() {
7 let catalog = Catalog::from([(
8 "Hello {name}!".to_owned(),
9 CatalogEntry {
10 translation: Some(CatalogTranslation::Singular("Hallo {name}!".to_owned())),
11 ..CatalogEntry::default()
12 },
13 )]);
14
15 let compiled = compile_catalog(&catalog, &CompileCatalogOptions::new("de"))
16 .expect("catalog should compile");
17 let key = generate_message_id("Hello {name}!", None);
18 let values = MessageValues::from([("name".to_owned(), MessageValue::from("Sebastian"))]);
19
20 println!("{}", compiled.format(&key, &values));
21}Sourcepub fn format_with_host<H: FormatHost>(
&self,
key: &str,
values: &MessageValues,
host: &H,
) -> String
pub fn format_with_host<H: FormatHost>( &self, key: &str, values: &MessageValues, host: &H, ) -> String
Format a message with a caller-provided host, returning the key itself if missing.
Trait Implementations§
Source§impl Clone for CompiledCatalog
impl Clone for CompiledCatalog
Source§fn clone(&self) -> CompiledCatalog
fn clone(&self) -> CompiledCatalog
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 moreAuto Trait Implementations§
impl Freeze for CompiledCatalog
impl RefUnwindSafe for CompiledCatalog
impl Send for CompiledCatalog
impl Sync for CompiledCatalog
impl Unpin for CompiledCatalog
impl UnsafeUnpin for CompiledCatalog
impl UnwindSafe for CompiledCatalog
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