pub struct Resource {
pub metadata: Metadata,
pub entries: Vec<Entry>,
}Expand description
A complete localization resource (corresponds to a .strings, .xml, .xcstrings, etc. file).
Contains metadata and all entries for a single language and domain.
Fields§
§metadata: MetadataOptional header-level metadata (language code, domain/project, etc.).
entries: Vec<Entry>Ordered list of all entries in this resource.
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn add_entry(&mut self, entry: Entry)
pub fn add_entry(&mut self, entry: Entry)
Add an entry to the resource.
use langcodec::types::{Resource, Entry, Translation, EntryStatus, Metadata};
use std::collections::HashMap;
let mut resource = Resource {
metadata: Metadata {
language: "en".to_string(),
domain: "test".to_string(),
custom: HashMap::new(),
},
entries: Vec::new(),
};
resource.add_entry(Entry {
id: "hello".to_string(),
value: Translation::Singular("Hello".to_string()),
status: EntryStatus::Translated,
comment: None,
custom: HashMap::new(),
});§Returns
The added entry.
Sourcepub fn find_entry(&self, id: &str) -> Option<&Entry>
pub fn find_entry(&self, id: &str) -> Option<&Entry>
Find an entry by its id.
use langcodec::types::{Resource, Entry, Translation, EntryStatus, Metadata};
use std::collections::HashMap;
let mut resource = Resource {
metadata: Metadata {
language: "en".to_string(),
domain: "test".to_string(),
custom: HashMap::new(),
},
entries: Vec::new(),
};
resource.add_entry(Entry {
id: "hello".to_string(),
value: Translation::Singular("Hello".to_string()),
status: EntryStatus::Translated,
comment: None,
custom: HashMap::new(),
});
let entry = resource.find_entry("hello").unwrap();
assert_eq!(entry.value, Translation::Singular("Hello".to_string()));
assert_eq!(entry.status, EntryStatus::Translated);
assert_eq!(entry.comment, None);Sourcepub fn find_entry_mut(&mut self, id: &str) -> Option<&mut Entry>
pub fn find_entry_mut(&mut self, id: &str) -> Option<&mut Entry>
Find a mutable entry by its id.
use langcodec::types::{Resource, Entry, Translation, EntryStatus, Metadata};
use std::collections::HashMap;
let mut resource = Resource {
metadata: Metadata {
language: "en".to_string(),
domain: "test".to_string(),
custom: HashMap::new(),
},
entries: Vec::new(),
};
resource.add_entry(Entry {
id: "hello".to_string(),
value: Translation::Singular("Hello".to_string()),
status: EntryStatus::Translated,
comment: None,
custom: HashMap::new(),
});
let entry = resource.find_entry_mut("hello").unwrap();
assert_eq!(entry.value, Translation::Singular("Hello".to_string()));
assert_eq!(entry.status, EntryStatus::Translated);
assert_eq!(entry.comment, None);
entry.value = Translation::Singular("Hello, World!".to_string());
entry.status = EntryStatus::NeedsReview;
entry.comment = Some("Hello, World!".to_string());
assert_eq!(entry.value, Translation::Singular("Hello, World!".to_string()));
assert_eq!(entry.status, EntryStatus::NeedsReview);
assert_eq!(entry.comment, Some("Hello, World!".to_string()));pub fn parse_language_identifier(&self) -> Option<LanguageIdentifier>
Sourcepub fn has_language(&self, lang: &str) -> bool
pub fn has_language(&self, lang: &str) -> bool
Check if this resource has a specific language.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Resource
impl<'de> Deserialize<'de> for Resource
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
impl Eq for Resource
impl StructuralPartialEq for Resource
Auto Trait Implementations§
impl Freeze for Resource
impl RefUnwindSafe for Resource
impl Send for Resource
impl Sync for Resource
impl Unpin for Resource
impl UnwindSafe for Resource
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