code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(43 lines)
1 '\" t
2 .\" Copyright (c) 2026 Bruce Hill
3 .\" All rights reserved.
4 .\"
5 .TH Text.translate 3 2026-03-08 "Tomo man-pages"
6 .SH NAME
7 Text.translate \- perform multiple replacements
8 .SH LIBRARY
9 Tomo Standard Library
10 .SH SYNOPSIS
11 .nf
12 .BI Text.translate\ :\ func(text:\ Text,\ translations:\ {Text:Text}\ ->\ Text)
13 .fi
14 .SH DESCRIPTION
15 Takes a table mapping target texts to their replacements and performs all the replacements in the table on the whole text. At each position, the first matching replacement is applied and the matching moves on to *after* the replacement text, so replacement text is not recursively modified. See Text.replace() for more information about replacement behavior.
18 .SH ARGUMENTS
20 .TS
21 allbox;
22 lb lb lbx
23 l l l.
24 Name Type Description
25 text Text The text to be translated.
26 translations {Text:Text} A table mapping from target text to its replacement.
27 .TE
28 .SH RETURN
29 The text with all occurrences of the targets replaced with their corresponding replacement text.
31 .SH EXAMPLES
32 .EX
33 text := "A <tag> & an ampersand".translate({
34 "&": "&amp;",
35 "<": "&lt;",
36 ">": "&gt;",
37 '"': "&quot",
38 "'": "&#39;",
39 })
40 assert text == "A &lt;tag&gt; &amp; an ampersand"
41 .EE
42 .SH SEE ALSO
43 .BR Tomo-Text (3)