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:
Orkun ÇAKILKAYA 2026-09-24 22:03:49 +03:00
parent 7605a0253c
commit 6bd3228990
9 changed files with 76 additions and 1 deletions

View file

@ -26,7 +26,9 @@ function ui_px(v: float) -> float {
if ui_be != null and ui_be.scale != null { return v * ui_be.scale() }
return v
}
var tr_no: bool = false # inside translate="no" while a frame is built
function ui_tr(s: string) -> string {
if tr_no { return s }
if ui_be != null and ui_be.translate != null { return ui_be.translate(s) }
return s
}

View file

@ -24,10 +24,14 @@ function bd_elem(k: UiTpl, e: UiEnv, key: string) -> UiNode {
if k.on_keys[i] == "press" { n.act = k.on_acts[i] }
}
lc_note(key, k.on_keys, k.on_acts, e)
let was_no = tr_no
let say = ui_attr_text(n, "translate")
if say == "no" { tr_no = true } else if say == "yes" { tr_no = false }
bd_kids(k.kids, e, key, n.children)
if k.text != null { el_text(n, ui_tr(ui_eval_text(k.text, e))) }
el_inline(n)
if k.tag == "input" or k.tag == "select" or k.tag == "progress" or k.tag == "meter" { ct_build(n) }
tr_no = was_no
return n
}
function el_kind(n: UiNode, tag: string) -> void {

View file

@ -30,6 +30,7 @@ import "popover.ludic"
import "popover_anchor.ludic"
import "popover_within.ludic"
import "tooltip.ludic"
import "tooltip_text.ludic"
import "life.ludic"
import "tpl.ludic"
import "tpl_lines.ludic"

View file

@ -16,7 +16,7 @@ function tt_track(scope: UiNode, x: float, y: float) -> void {
tt_key = n.key
tt_since = an_now()
}
tt_text = ui_tr(ui_attr_text(n, "title"))
tt_text = tt_translate(n, ui_attr_text(n, "title"))
tt_x = x
tt_y = y
}

View file

@ -0,0 +1,18 @@
# tooltip_text.ludic - a title in the program's language: the whole of it when the translator knows
# it, else line by line; and not at all inside translate="no" (the nearest translate= out from it)
function tt_translate(n: UiNode, s: string) -> string {
var at = n
while at != null {
let say = ui_attr_text(at, "translate")
if say == "no" { return s }
if say == "yes" { break }
at = at.parent
}
let whole = ui_tr(s)
if whole != s { return whole }
let lines = tt_lines(s)
if len(lines) < 2 { return whole }
var out = ui_tr(lines[0])
for i in 1 .. len(lines) { out = out + "\n" + ui_tr(lines[i]) }
return out
}