Expand description
Bilingua document model: what every file parser extracts and what it writes back.
A parser (Filter) turns a source file into a Document: translatable Units (a paragraph, a cell, a
string) and a Skeleton that holds everything else byte for byte. Each unit holds one or more
Segments (one before segmentation; sentences after bilingua-seg splits it). Formatting inside the text
is kept as inline Inline::Tag codes whose original markup lives in Unit::codes, so a writer can put
it back exactly.
JSON shape: Inline and TagKind serialise exactly like catcore::Inline and catcore::TagKind
({"text": ".."} / {"tag": {"id", "kind": "open|close|standalone", "display"}}), so one editor UI shows
bilingual files (catcore) and source files (Bilingua) the same way. Every field added since is optional and
left out of the JSON when empty: a tag’s free flag, a segment’s origin, a unit’s notes and lock_reason,
a skeleton’s parser.
Bilingual files (XLIFF and the like) use the same model: a segment may carry a target, a state and an origin (with a match percentage), and a unit may carry notes and a lock reason. Monolingual formats leave them empty.
profile holds what one consumer needs and no other (the Localization OS profile, and
profile::tokens, which converts inline codes to and from LocOS’s text tokens, one token per tag).
Re-exports§
pub use guard::LimitError;pub use guard::LimitKind;pub use guard::Limits;pub use pytext::py_is_word_char;pub use pytext::py_is_word_start_char;pub use pytext::py_isdecimal_char;pub use pytext::py_isalnum_char;pub use pytext::py_isalpha_char;pub use pytext::py_isspace_char;pub use pytext::py_has_alnum;pub use pytext::py_has_alpha;pub use pytext::py_isalnum;pub use pytext::py_isalpha;pub use pytext::py_isspace;pub use pytext::py_lstrip;pub use pytext::py_rstrip;pub use pytext::py_strip;pub use encoding_rs;
Modules§
- b64
- Raw bytes in JSON as a base64 string (standard alphabet, padded). Reading also accepts the old form, an array of integers, so skeletons saved before this change still load.
- codepage
- Windows code pages per language: which legacy encoding an undeclared, non-UTF-8 text file most likely uses
when its project’s source language is known (Localization OS decision 22,
code_pages.py). - enc
- Reading and writing text files in the encoding they came in (Localization OS
read_text_upload, decisions 22 and B-bytes). - garble
- “The decoded letters look wrong”: the script-mix checks Localization OS runs on a text it had to read with a
guessed code page (
text_looks_garbled, decision 22). Heuristics, deliberately conservative: a warning is never an error. - guard
- Safety limits and the XML guard, one place for every parser (D27 step 5).
- profile
- Profiles: named sets of choices one consumer of Bilingua needs, kept out of the general API. There is one,
locos: what the Localization OS adapter needs to give LocOS the files and ids it had before Bilingua. - pytext
- Python’s character tests, exactly:
str.isalpha,str.isalnumandstr.isspaceof Python 3.13 (Unicode 15.1), which Localization OS uses for its “has a letter or digit” and whitespace rules.
Macros§
- parser_
info - The producing parser of the running crate:
parser_info!()expands to aParserInfowith the calling crate’s name, version andcrate::SKELETON_SCHEMA. Every format crate defines that constant (pub const SKELETON_SCHEMA: u32 = 1;) and bumps it only when its skeleton changes.parser_info!(n)stamps an explicit schema instead.
Structs§
- Code
Data - The original markup of one inline code, kept so the writer can reproduce it.
A paired code fills
openandclose; a standalone code fillsstandalone. Build it withCodeData::paired,CodeData::standaloneorCodeData::newand thewith_*methods. - Document
- An extracted file: its units and its skeleton. Build it with
Document::newand thewith_*methods; edit targets withDocument::set_targetand friends, which check the tags.Defaultis an empty document of no format (no writer accepts it). - Extract
Options - Options for
Filter::extract. Build them withExtractOptions::newand thewith_*methods (ExtractOptions::new().with_target_lang("de-DE")); new options are added without breaking callers. - Format
Option Key - One option a format understands in
ExtractOptions::format_options: its full key ("csv.columns"), the kind of value, and a line of help for tools that list the options. - Merge
Options - Options for
Filter::merge_with. The default is whatFilter::mergedoes. They live here, once, and every format that stamps a language, fills plurals or writes text honours them: - Note
- A comment on a unit: a translator query, a developer instruction, a reviewer remark. Build it with
Note::new. - Origin
- How a target came to be, with the match percentage when it came from memory. Build it with
Origin::new. - Parser
Info - Which parser made a skeleton: the crate name, its version (for information) and the skeleton schema number.
The schema is an integer each format crate bumps only when its skeleton layout changes, so a new crate release
that did not touch the layout still merges old skeletons (see
check_parser). - Segment
- One translatable piece of a unit: its source, and its target once there is one. Build it with
Segment::newand thewith_*methods. - Unit
- 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::neworUnit::from_segmentsand thewith_*methods. - Unit
Context - What helps a translator, an AI lane or a preview understand a unit. Build it with
UnitContext::newand thewith_*methods;extratakes anything without a field of its own. - Warning
- A notice about a file that was read anyway: it never stops a merge.
kindis a stable word for programs (“text_encoding”);messageis plain text safe to show the person who uploaded the file. - ZipEntry
- One entry of a zip skeleton, in the archive’s order. Build it with
ZipEntry::neworZipEntry::raw.
Enums§
- Error
- Every Bilingua failure. Match with a wildcard arm: a 1.x release may add variants.
- Granularity
- How finely units are split into segments.
- Inline
- One piece of segment content, in logical order.
- Option
Kind - The kind of value a format option takes.
- Origin
Kind - Where a segment’s target came from. Match with a wildcard arm: a 1.x release may add kinds (a JSON file with
a kind this release does not know reads as
Other). - Output
Encoding - How a merge writes text files.
- SegState
- Where a segment is in its life, from untouched to signed off. Monolingual files only use
New,Draft,TranslatedandConfirmed; bilingual files and review workflows use the rest. - Skel
Part - One piece of a text skeleton: literal output, or the place where a unit’s text goes. Closed: anything else a
format needs lives in its own parts’ text or in
Unit::hidden. - Skeleton
- Everything in the file that is not translatable text. New kinds of skeleton come as new variants (match with a
wildcard arm); the fields of each variant are fixed for 1.x (a format records more in its parts, in the
encodingtag’s;name=valueitems, or inUnit::hidden). - TagKind
- The kind of an inline code. Closed: a code opens, closes or stands alone.
- ZipData
- The content of one zip entry in a skeleton. Closed: copied bytes or rebuilt text.
Traits§
- Filter
- A file parser. Implementations live in one crate per format (
bilingua-html,bilingua-docx, …). - Into
Option String - What a builder takes for an optional text field:
"de-DE", aString, or anOptionof either (Noneclears the field).impl Into<Option<String>>would refuse a plain&str, so the builders take this instead.
Functions§
- check_
format_ options - Checks every
format_optionsentry against the keys the filters declare: an unknown key or a value of the wrong kind is anError::FormatOption. Thebilinguafacade calls this with every filter’s keys, so an option meant for another format (the adapter sendsdocx.translate_commentswith every file) is accepted. - check_
option_ map check_format_optionsfor any map of options (MergeOptions::format_optionstoo).- check_
own_ options - The check every filter makes when it is called directly (not through the
bilinguafacade), first thing inextract(with&opts.format_options) and inmerge_with(with itsMergeOptions::format_options): an option in one of the filter’s own families (its id, and the<family>.prefix of every key it declares) that it does not declare is refused (a misspeltcsv.columswould otherwise be ignored), and so is a value of the wrong kind for a key it declares. Keys of other formats are left alone: one option map may be meant for many formats, and only the facade, which knows every filter’s keys, can tell a good foreign key from a misspelt one. - check_
parser - Refuses a document whose skeleton came from another crate or from a newer schema than
current. Older schemas and skeletons with no record (written before stamps existed) are accepted; a crate that stops reading some old schema usescheck_parser_min. - check_
parser_ min - Like
check_parser, but also refuses schemas older thanoldest, the oldest one the crate still reads. - merge_
text - Joins neighbouring
Textpieces. - plain_
text - Plain text with the tags removed.