commit 6b7046bc9f01f950c196b014624ae22889cd25d6
parent 877df588ae7d2804a915e69411ca92aab650c21d
Author: lash <dev@holbrook.no>
Date: Thu, 2 Jan 2025 07:30:47 +0000
Add menu translation handling
Diffstat:
3 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/debug/node.go b/debug/node.go
@@ -8,6 +8,7 @@ type Node struct {
var (
NodeIndex = make(map[string]Node)
+ MenuIndex = make(map[string]int)
)
func (n *Node) haveConn(peer string) bool {
@@ -45,3 +46,13 @@ func (n *Node) Next() *Node {
n.conn = n.conn[1:]
return &r
}
+
+func AddMenu(s string) int {
+ var ok bool
+ _, ok = MenuIndex[s]
+ if !ok {
+ MenuIndex[s] = 0
+ }
+ MenuIndex[s] += 1
+ return MenuIndex[s]
+}
diff --git a/debug/parse.go b/debug/parse.go
@@ -12,6 +12,7 @@ var (
type NodeParseHandler struct {
*vm.ParseHandler
node *Node
+ parentMOutFunc func(string, string) error
parentMoveFunc func(string) error
parentInCmpFunc func(string, string) error
parentCatchFunc func(string, uint32, bool) error
@@ -26,12 +27,20 @@ func NewNodeParseHandler(node *Node) *NodeParseHandler {
np.parentMoveFunc = np.ParseHandler.Move
np.parentInCmpFunc = np.ParseHandler.InCmp
np.parentCatchFunc = np.ParseHandler.Catch
+ np.parentMOutFunc = np.ParseHandler.MOut
np.Move = np.move
np.InCmp = np.incmp
np.Catch = np.catch
+ np.MOut = np.mout
return np
}
+func (np *NodeParseHandler) mout(sym string, sel string) error {
+ c := AddMenu(sym)
+ logg.Infof("add MOUT", "sym", sym, "visited", c)
+ return np.parentMOutFunc(sym, sel)
+}
+
func (np *NodeParseHandler) move(sym string) error {
var node Node
diff --git a/dev/walk/main.go b/dev/walk/main.go
@@ -67,9 +67,42 @@ func(tr *translator) Close() error {
return err
}
+func(tr *translator) process(s string) error {
+ return nil
+}
+
+func(tr *translator) menuFunc(sym string) error {
+ var v string
+
+ for k, w := range(tr.w) {
+ var s string
+ ln, err := lang.LanguageFromCode(k)
+ ctx := context.WithValue(tr.ctx, "Language", ln)
+ r, err := tr.rs.GetMenu(ctx, sym)
+ for _, v = range(strings.Split(r, "\n")) {
+ s += fmt.Sprintf("\t\"%s\"\n", v)
+ }
+ s = fmt.Sprintf(`msgid ""
+ "%s"
+msgstr ""
+%s
+
+`, sym, s)
+ if err == nil {
+ logg.DebugCtxf(tr.ctx, "menu translation found", "node", sym)
+ _, err = w.Write([]byte(s))
+ if err != nil {
+ return err
+ }
+ } else {
+ logg.DebugCtxf(tr.ctx, "no menuitem translation found", "node", sym)
+ }
+ }
+ return nil
+}
+
func(tr *translator) nodeFunc(node *debug.Node) error {
var v string
- fmt.Fprintf(os.Stderr, "processing node: %v\n", node)
for k, w := range(tr.w) {
var s string
@@ -185,4 +218,14 @@ func main() {
os.Exit(1)
}
}
+
+ for k, _ := range(debug.MenuIndex) {
+ logg.Tracef("processing menu", "sym", k)
+ err = tr.menuFunc(k)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "translate process error for menu %s: %v", k, err)
+ os.Exit(1)
+ }
+ }
+
}