#[non_exhaustive]pub struct Segment {
pub id: String,
pub source: Vec<Inline>,
pub target: Vec<Inline>,
pub state: SegState,
pub origin: Option<Origin>,
pub empty_target: bool,
}Expand description
One translatable piece of a unit: its source, and its target once there is one. Build it with
Segment::new 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: <unit id> when the unit has one segment, else <unit id>#<n> (1-based).
source: Vec<Inline>The source text with its inline codes.
target: Vec<Inline>Empty = untranslated, unless empty_target says the translation is empty on purpose (see below).
state: SegStateWhere the segment is in its life (new, draft, translated, …).
origin: Option<Origin>Where the target came from. None for monolingual files and for targets nobody labelled.
empty_target: boolTranslated to nothing on purpose. The empty-translation rule: a segment with an empty target is
untranslated and the writer keeps its source text, unless empty_target is true; then the segment counts as
translated (Segment::has_target) and the writer writes nothing for it. Document::set_target_empty
sets it; Document::set_target with any target clears it. Left out of the JSON when false. (Localization
OS writes an empty target as an empty value or paragraph: its adapter sets this flag for an empty LocOS
target.)
Implementations§
Source§impl Segment
impl Segment
Sourcepub fn new(id: impl Into<String>, source: Vec<Inline>) -> Segment
pub fn new(id: impl Into<String>, source: Vec<Inline>) -> Segment
An untranslated segment (no target, state New, no origin).
Sourcepub fn has_target(&self) -> bool
pub fn has_target(&self) -> bool
True when the segment is translated: it has a target, or it was translated to nothing on purpose.
Sourcepub fn output(&self) -> &[Inline]
pub fn output(&self) -> &[Inline]
The text to write: the target, nothing for an empty translation, or the source when untranslated.
Sourcepub fn with_empty_target(self, empty_target: bool) -> Segment
pub fn with_empty_target(self, empty_target: bool) -> Segment
Marks (or unmarks) the segment as translated to nothing on purpose; marking clears the target.
Sourcepub fn with_target(self, target: Vec<Inline>) -> Segment
pub fn with_target(self, target: Vec<Inline>) -> Segment
Sets the target as it is (no tag check: use Document::set_target for edits).
Sourcepub fn with_state(self, state: SegState) -> Segment
pub fn with_state(self, state: SegState) -> Segment
Sets the state.