#[non_exhaustive]pub struct Unit {
pub id: String,
pub segments: Vec<Segment>,
pub separators: Vec<String>,
pub codes: BTreeMap<String, CodeData>,
pub context: UnitContext,
pub translate: bool,
pub notes: Vec<Note>,
pub lock_reason: Option<String>,
pub hidden: BTreeMap<String, String>,
}Expand description
One translatable unit of the file (a paragraph, a cell, a string): its segments, the original markup of its
inline codes and its context. Build it with Unit::new or Unit::from_segments and the with_* methods.
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.id: StringUnique within the document, stable for the same input file.
segments: Vec<Segment>One segment before sentence splitting; one per sentence after.
separators: Vec<String>Text between segments as it appeared in the source (spaces after a full stop). Always
segments.len() - 1 entries; the writer joins segment targets with these.
codes: BTreeMap<String, CodeData>Original markup per inline code id.
context: UnitContextWhat helps a translator understand the unit.
translate: boolFalse for content shown for context only (locked).
notes: Vec<Note>Comments attached to the unit in a bilingual file. (Source files keep theirs in context.notes.)
lock_reason: Option<String>Why the unit is locked (“context match”, “locked by the project”). Free text, usually with
translate == false.
What the parser needs to write the unit back and nobody else sees: the value as written in the file, its
white space, a layout flag. Keyed by a short name the parser picks (“raw”, “lead”). It is not an inline code,
so editors, the LocOS token map and tag checks never see it. Left out of the JSON when empty. (Parsers used
to keep this in codes under ~ names; such codes in an old JSON document are moved here when it is read.)
Implementations§
Source§impl Unit
impl Unit
Sourcepub fn new(id: impl Into<String>, source: Vec<Inline>) -> Unit
pub fn new(id: impl Into<String>, source: Vec<Inline>) -> Unit
A unit with one segment holding source.
Sourcepub fn from_segments(id: impl Into<String>, segments: Vec<Segment>) -> Unit
pub fn from_segments(id: impl Into<String>, segments: Vec<Segment>) -> Unit
A unit made of the given segments (their ids are kept as they are). Separators start empty, one per gap.
A hidden value (see Unit::hidden).
Sets a hidden value.
True when the hidden value is set (a flag).
Sets a hidden value (builder form of Unit::set_hidden).
Sourcepub fn with_separators(self, separators: Vec<String>) -> Unit
pub fn with_separators(self, separators: Vec<String>) -> Unit
Replaces the separators (one per gap between segments).
Sourcepub fn with_codes(self, codes: BTreeMap<String, CodeData>) -> Unit
pub fn with_codes(self, codes: BTreeMap<String, CodeData>) -> Unit
Replaces the original markup of the inline codes.
Sourcepub fn with_code(self, id: impl Into<String>, code: CodeData) -> Unit
pub fn with_code(self, id: impl Into<String>, code: CodeData) -> Unit
Adds (or replaces) the original markup of one inline code.
Sourcepub fn with_context(self, context: UnitContext) -> Unit
pub fn with_context(self, context: UnitContext) -> Unit
Sets the context.
Sourcepub fn with_translate(self, translate: bool) -> Unit
pub fn with_translate(self, translate: bool) -> Unit
Sets whether the unit is translatable (false: shown for context only).
Sourcepub fn with_notes(self, notes: Vec<Note>) -> Unit
pub fn with_notes(self, notes: Vec<Note>) -> Unit
Replaces the bilingual-file notes.
Sourcepub fn with_lock_reason(self, reason: impl IntoOptionString) -> Unit
pub fn with_lock_reason(self, reason: impl IntoOptionString) -> Unit
Sets (or with None clears) why the unit is locked.
Sourcepub fn source(&self) -> Vec<Inline>
pub fn source(&self) -> Vec<Inline>
The whole unit’s source, segments joined with their separators.
Sourcepub fn output(&self) -> Vec<Inline>
pub fn output(&self) -> Vec<Inline>
The text to write for this unit: each segment’s target, or its source when the segment is untranslated
(as every CAT tool does), or nothing for a segment translated to empty (Segment::empty_target).
Sourcepub fn is_translated(&self) -> bool
pub fn is_translated(&self) -> bool
True when some segment of a translatable unit is translated (has a target or an empty translation).