#[non_exhaustive]pub struct MergeOptions {
pub output_encoding: OutputEncoding,
pub stamp_target_always: bool,
pub profile: Option<String>,
pub format_options: BTreeMap<String, String>,
pub limits: Option<Limits>,
}Expand description
Options for Filter::merge_with. The default is what Filter::merge does. They live here, once, and
every format that stamps a language, fills plurals or writes text honours them:
output_encoding:OutputEncoding::KeeporOutputEncoding::Utf8(throughenc::encode_text_with, so every text format that keeps its encoding in the skeleton gets it).stamp_target_always: by default a merge in which nothing is translated returns the original bytes (no target language stamp, no plural fill, no format conversion). Withtruethe target language is stamped and missing plural forms are filled even then, as Localization OS does. It only has an effect whenDocument::target_langis set.
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.output_encoding: OutputEncodingKeep the file’s encoding, or write UTF-8.
stamp_target_always: boolStamp the target language and fill plurals even when nothing is translated.
profile: Option<String>The profile the document is written for (see ExtractOptions::profile); format crates may switch on it.
format_options: BTreeMap<String, String>Merge-time format options, as for ExtractOptions::format_options (checked against the same keys).
limits: Option<Limits>Safety limits for a merge that reads a stored package again (EPUB, MadCap Flare); None uses
Limits::default. They are the caller’s policy: a merge never takes limits from the document, so a file
extracted under raised limits is merged under the same ones only when the caller passes them here again.
Implementations§
Source§impl MergeOptions
impl MergeOptions
Sourcepub fn new() -> MergeOptions
pub fn new() -> MergeOptions
The defaults: keep the file’s encoding, no stamp when nothing is translated (what Filter::merge does).
Sourcepub fn with_output_encoding(
self,
output_encoding: OutputEncoding,
) -> MergeOptions
pub fn with_output_encoding( self, output_encoding: OutputEncoding, ) -> MergeOptions
Sets the output encoding.
Sourcepub fn with_stamp_target_always(self, stamp_target_always: bool) -> MergeOptions
pub fn with_stamp_target_always(self, stamp_target_always: bool) -> MergeOptions
Sets the stamp rule.
Sourcepub fn with_profile(self, profile: impl IntoOptionString) -> MergeOptions
pub fn with_profile(self, profile: impl IntoOptionString) -> MergeOptions
Switches a profile on ("locos"), or off with None.
Sourcepub fn is_profile(&self, name: &str) -> bool
pub fn is_profile(&self, name: &str) -> bool
True when this profile is on.
Sourcepub fn with_limits(self, limits: impl Into<Option<Limits>>) -> MergeOptions
pub fn with_limits(self, limits: impl Into<Option<Limits>>) -> MergeOptions
Sets the safety limits for this merge, or None for Limits::default.
Sourcepub fn with_format_option(
self,
key: impl Into<String>,
value: impl ToString,
) -> MergeOptions
pub fn with_format_option( self, key: impl Into<String>, value: impl ToString, ) -> MergeOptions
Sets one format option ("<format>.<name>").
Sourcepub fn with_format_options(
self,
options: BTreeMap<String, String>,
) -> MergeOptions
pub fn with_format_options( self, options: BTreeMap<String, String>, ) -> MergeOptions
Replaces all format options.
Sourcepub fn any_translated(doc: &Document) -> bool
pub fn any_translated(doc: &Document) -> bool
True when the document has at least one segment with a target.
Sourcepub fn should_stamp(&self, doc: &Document) -> bool
pub fn should_stamp(&self, doc: &Document) -> bool
Should a format stamp the target language and fill plurals for this document? target_lang must be set (and
not blank) and something translated, or stamp_target_always. “Translated” is MergeOptions::any_translated;
a format with its own notion of a change uses MergeOptions::stamp_lang.
Sourcepub fn plausible_lang(code: &str) -> bool
pub fn plausible_lang(code: &str) -> bool
Can this text be a language code in any spelling a format writes (de-DE, zh_Hant, sr@latin,
de_DE.UTF-8)? ASCII letters, digits, -, _, @ and ., at most 64 bytes. The target language is free
text (a host setting, or the trgLang of a returned XLIFF), and several formats write it into a header
line or a key; anything else, a line break above all, is never stamped.
Sourcepub fn stamp_lang<'a>(
&self,
doc: &'a Document,
translated: bool,
) -> Option<&'a str>
pub fn stamp_lang<'a>( &self, doc: &'a Document, translated: bool, ) -> Option<&'a str>
The one stamp rule every format uses: the document’s target_lang (trimmed, and only when it can be a
language code, see MergeOptions::plausible_lang) when translated (the format’s own “something was
written” test) or stamp_target_always, else None.