#[non_exhaustive]pub struct UnitContext {
pub kind: Option<String>,
pub style: Option<String>,
pub key: Option<String>,
pub heading: Option<String>,
pub location: Option<String>,
pub max_len: Option<usize>,
pub notes: Vec<String>,
pub extra: BTreeMap<String, String>,
}Expand description
What helps a translator, an AI lane or a preview understand a unit. Build it with UnitContext::new and the
with_* methods; extra takes anything without a field of its own.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.kind: Option<String>What the unit is: “heading”, “paragraph”, “list-item”, “cell”, “button”, “title”, “alt”, “key”, “subtitle”, … Free text; parsers use the most specific word they know.
style: Option<String>Style or element name as the file has it, e.g. “Heading 2”, “h2”, “td”.
key: Option<String>Resource key or path for key/value formats (JSON pointer, PO msgctxt + msgid, subtitle number).
heading: Option<String>Nearest heading text above the unit, when the format has headings.
location: Option<String>Location in the original, readable: word/document.xml paragraph 12, /html/body/main/p[3].
max_len: Option<usize>Maximum length in characters, when the file states one.
notes: Vec<String>Comments or notes attached in the file (translator comments, PO comments, DOCX comments).
extra: BTreeMap<String, String>Subtitle timing and similar extras the editor may show.
Implementations§
Source§impl UnitContext
impl UnitContext
Sourcepub fn new() -> UnitContext
pub fn new() -> UnitContext
An empty context.
Sourcepub fn with_kind(self, kind: impl IntoOptionString) -> UnitContext
pub fn with_kind(self, kind: impl IntoOptionString) -> UnitContext
Sets (or with None clears) what the unit is (“heading”, “cell”, …).
Sourcepub fn with_style(self, style: impl IntoOptionString) -> UnitContext
pub fn with_style(self, style: impl IntoOptionString) -> UnitContext
Sets (or clears) the style or element name.
Sourcepub fn with_key(self, key: impl IntoOptionString) -> UnitContext
pub fn with_key(self, key: impl IntoOptionString) -> UnitContext
Sets (or clears) the resource key or path.
Sourcepub fn with_heading(self, heading: impl IntoOptionString) -> UnitContext
pub fn with_heading(self, heading: impl IntoOptionString) -> UnitContext
Sets (or clears) the nearest heading.
Sourcepub fn with_location(self, location: impl IntoOptionString) -> UnitContext
pub fn with_location(self, location: impl IntoOptionString) -> UnitContext
Sets (or clears) the readable location.
Sourcepub fn with_max_len(self, max_len: Option<usize>) -> UnitContext
pub fn with_max_len(self, max_len: Option<usize>) -> UnitContext
Sets (or clears) the maximum length in characters.
Sourcepub fn with_notes(self, notes: Vec<String>) -> UnitContext
pub fn with_notes(self, notes: Vec<String>) -> UnitContext
Replaces the notes.
Sourcepub fn with_extra(self, extra: BTreeMap<String, String>) -> UnitContext
pub fn with_extra(self, extra: BTreeMap<String, String>) -> UnitContext
Replaces the extras.