#[non_exhaustive]pub struct Unit {
pub id: String,
pub segments: Vec<Segment>,
pub separators: Vec<String>,
pub codes: Codes,
pub context: UnitContext,
pub translate: bool,
pub notes: Vec<Note>,
pub lock_reason: Option<String>,
pub hidden: TextMap,
pub plural: Option<Box<PluralSlot>>,
}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: CodesOriginal 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.)
plural: Option<Box<PluralSlot>>The plural group this unit is one form of (see PluralSlot); None for most units and under the LocOS
profile. Left out of the JSON when unset. No writer reads it.
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).
Every hidden value, read-only.
Every hidden value, to change in place.
Replaces the hidden values (a TextMap, or a BTreeMap<String, String>).
Sourcepub fn codes(&self) -> &Codes
pub fn codes(&self) -> &Codes
The original markup of the inline codes, read-only. Prefer it to the field.
Sourcepub fn codes_mut(&mut self) -> &mut Codes
pub fn codes_mut(&mut self) -> &mut Codes
The original markup of the inline codes, to change in place (see Unit::codes).
Sourcepub fn set_codes(&mut self, codes: impl Into<Codes>)
pub fn set_codes(&mut self, codes: impl Into<Codes>)
Replaces the original markup of the inline codes (a Codes, or a BTreeMap<String, CodeData>).
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: impl Into<Codes>) -> Unit
pub fn with_codes(self, codes: impl Into<Codes>) -> Unit
Replaces the original markup of the inline codes (a Codes, or a BTreeMap<String, CodeData>).
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).
Source§impl Unit
impl Unit
Sourcepub fn plural(&self) -> Option<&PluralSlot>
pub fn plural(&self) -> Option<&PluralSlot>
The plural group this unit is one form of, if any.
Sourcepub fn plural_mut(&mut self) -> Option<&mut PluralSlot>
pub fn plural_mut(&mut self) -> Option<&mut PluralSlot>
The plural slot, to change in place.
Sourcepub fn set_plural(&mut self, plural: impl Into<Option<PluralSlot>>)
pub fn set_plural(&mut self, plural: impl Into<Option<PluralSlot>>)
Sets (or with None clears) the plural slot.
Sourcepub fn with_plural(self, plural: impl Into<Option<PluralSlot>>) -> Unit
pub fn with_plural(self, plural: impl Into<Option<PluralSlot>>) -> Unit
Sets the plural slot (builder form of Unit::set_plural).