pub struct TextTable { /* private fields */ }Expand description
A per-language table that replaces bodies.
Keys are module.label#id (the same form as passed stop points). Values are bodies in the same form as the original.
Pass it to the VM with Vm::set_texts.
Implementations§
Source§impl TextTable
impl TextTable
Sourcepub fn new(language: impl Into<String>) -> Self
pub fn new(language: impl Into<String>) -> Self
Makes an empty table. language is the name of the language (such as en; the core gives it no meaning).
Sourcepub fn insert(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> Result<(), TextError>
pub fn insert( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> Result<(), TextError>
Puts a translation. If the same key exists, replaces it.
A translation is a body in the same form as the original. Body escapes (\「 \」 \$ \\ \= \#) can be used.
${n} (n is an integer of 1 or more) becomes the value of the n-th ${expr} of the original. Any other \
combinations and ${…} are errors (the table is unchanged). Whether n exceeds the count in the original is not
checked here, because the scripts are unknown (Vm::set_texts and TextTable::check check
it).
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Returns (key, translation) in insertion order.
Sourcepub fn check(&self, program: &Program) -> Vec<TextIssue>
pub fn check(&self, program: &Program) -> Vec<TextIssue>
Checks against the scripts. Results are in script order (missing translations, number errors), followed by table order (extra translations).
- Missing translation (warning): a key of a body with a stable ID in the scripts that is not in the table.
- Extra translation (warning): a key in the table that is not in the scripts.
- Number error (error): the
nof${n}exceeds the number of${expr}in the original.
Sourcepub fn template(program: &Program, language: impl Into<String>) -> Self
pub fn template(program: &Program, language: impl Into<String>) -> Self
Makes a table (a template) whose translations are the originals, for all bodies with stable IDs in the scripts.
${expr} becomes a numbered ${n} (in the order written). Translators rewrite it into translations.
Sourcepub fn from_file(source: &str) -> Result<Self, TextError>
pub fn from_file(source: &str) -> Result<Self, TextError>
Reads a table from the text of a file (a line-oriented format for tools; section 5.7 of spec/host/05-texts.md).
- Empty lines are skipped. Lines starting with
#are comments. - A line
@lang languagesets the language name (empty if absent). - Other lines are
keyTABtranslation. In translations,\nis a newline,\ta TAB and\ra carriage return. Other\sequences are translation escapes (such as\\). - A key appearing twice, or a translation that is an error in
TextTable::insert, gives an error with the line.
Sourcepub fn to_file(&self) -> String
pub fn to_file(&self) -> String
Turns the table into the text of a file (it can be read back with TextTable::from_file).