Skip to main content

Unit

Struct Unit 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: String

Unique 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: Codes

Original markup per inline code id.

§context: UnitContext

What helps a translator understand the unit.

§translate: bool

False 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.

§hidden: TextMap

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

Source

pub fn new(id: impl Into<String>, source: Vec<Inline>) -> Unit

A unit with one segment holding source.

Source

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.

Source

pub fn hidden(&self, key: &str) -> Option<&str>

A hidden value (see Unit::hidden).

Source

pub fn set_hidden(&mut self, key: impl Into<String>, value: impl Into<String>)

Sets a hidden value.

Source

pub fn has_hidden(&self, key: &str) -> bool

True when the hidden value is set (a flag).

Source

pub fn with_hidden( self, key: impl Into<String>, value: impl Into<String>, ) -> Unit

Sets a hidden value (builder form of Unit::set_hidden).

Source

pub fn hidden_map(&self) -> &TextMap

Every hidden value, read-only.

Source

pub fn hidden_map_mut(&mut self) -> &mut TextMap

Every hidden value, to change in place.

Source

pub fn set_hidden_map(&mut self, hidden: impl Into<TextMap>)

Replaces the hidden values (a TextMap, or a BTreeMap<String, String>).

Source

pub fn codes(&self) -> &Codes

The original markup of the inline codes, read-only. Prefer it to the field.

Source

pub fn codes_mut(&mut self) -> &mut Codes

The original markup of the inline codes, to change in place (see Unit::codes).

Source

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>).

Source

pub fn with_separators(self, separators: Vec<String>) -> Unit

Replaces the separators (one per gap between segments).

Source

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>).

Source

pub fn with_code(self, id: impl Into<String>, code: CodeData) -> Unit

Adds (or replaces) the original markup of one inline code.

Source

pub fn with_context(self, context: UnitContext) -> Unit

Sets the context.

Source

pub fn with_translate(self, translate: bool) -> Unit

Sets whether the unit is translatable (false: shown for context only).

Source

pub fn with_notes(self, notes: Vec<Note>) -> Unit

Replaces the bilingual-file notes.

Source

pub fn with_lock_reason(self, reason: impl IntoOptionString) -> Unit

Sets (or with None clears) why the unit is locked.

Source

pub fn source(&self) -> Vec<Inline>

The whole unit’s source, segments joined with their separators.

Source

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).

Source

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

Source

pub fn plural(&self) -> Option<&PluralSlot>

The plural group this unit is one form of, if any.

Source

pub fn plural_mut(&mut self) -> Option<&mut PluralSlot>

The plural slot, to change in place.

Source

pub fn set_plural(&mut self, plural: impl Into<Option<PluralSlot>>)

Sets (or with None clears) the plural slot.

Source

pub fn with_plural(self, plural: impl Into<Option<PluralSlot>>) -> Unit

Sets the plural slot (builder form of Unit::set_plural).

Trait Implementations§

Source§

impl Clone for Unit

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Unit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Unit

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Unit

Source§

impl PartialEq for Unit

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Unit

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Unit

Auto Trait Implementations§

§

impl Forget for Unit

§

impl Freeze for Unit

§

impl Move for Unit

§

impl RefUnwindSafe for Unit

§

impl Send for Unit

§

impl Sync for Unit

§

impl Unpin for Unit

§

impl UnsafeUnpin for Unit

§

impl UnwindSafe for Unit

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.