feat(ui): translate="no", and a title of several lines translated whole or line by line
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7605a0253c
commit
6bd3228990
9 changed files with 76 additions and 1 deletions
44
examples/library/ui_translate.ludic
Normal file
44
examples/library/ui_translate.ludic
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# ui_translate.ludic — translation: translate="no" keeps an element's text (and everything inside it)
|
||||
# as written, translate="yes" inside it translates again; a title of several lines is translated whole
|
||||
# when the translator knows it whole, else line by line, and not inside translate="no".
|
||||
import "ludic.ui"
|
||||
program UiTranslate {
|
||||
numbers float
|
||||
var said: []string = new []string
|
||||
var now: float = 0.0
|
||||
const PAGE: string = "<ui><screen name='t'><p>Hello</p><p translate='no'>Hello</p><div translate='no'><p>Hello</p><p translate='yes'>Hello</p></div><p class='a' title='Save\\nQuit'>a</p><p class='b' title='Line one\\nLine two'>b</p><div translate='no'><p class='c' title='Line one\\nLine two'>c</p></div></screen></ui>"
|
||||
function tr(s: string) -> string {
|
||||
if s == "Hello" { return "Merhaba" }
|
||||
if s == "Save\\nQuit" { return "Kaydet ve cik" }
|
||||
if s == "Line one" { return "Satir bir" }
|
||||
if s == "Line two" { return "Satir iki" }
|
||||
return s
|
||||
}
|
||||
function rec_text(x: float, y: float, s: string, size: float, c: int, a: float) -> void { push(said, s) }
|
||||
function clock() -> float { return now }
|
||||
function tip(root: UiNode, k: int) -> string {
|
||||
let n = root.children[k]
|
||||
let i = new UiInput
|
||||
i.x = n.x + 1.0
|
||||
i.y = n.y + 1.0
|
||||
ui_input(i)
|
||||
ui_show("t", null, 0.0, 0.0, 400.0, 400.0)
|
||||
now = now + 1.0
|
||||
said = new []string
|
||||
ui_input(i)
|
||||
ui_show("t", null, 0.0, 0.0, 400.0, 400.0)
|
||||
return `{said[len(said) - 2]}/{said[len(said) - 1]}`
|
||||
}
|
||||
entry {
|
||||
let b = new UiBackend
|
||||
b.text = fn rec_text
|
||||
ui_backend(b)
|
||||
ui_translator(fn tr)
|
||||
ui_clock(fn clock)
|
||||
ui_load_text(PAGE, "t.xml")
|
||||
let root: UiNode = ui_nodes("t", null)
|
||||
ui_place(root, 0.0, 0.0, 400.0, 400.0)
|
||||
let texts = `{root.children[0].text} {root.children[1].text} {root.children[2].children[0].text} {root.children[2].children[1].text}`
|
||||
print(`{texts} | {tip(root, 3)} | {tip(root, 4)} | {tip(root, 5)}`)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue