From 507dd5930e770154996474d4418d992f289b10f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Thu, 28 Dec 2023 14:28:59 +0100 Subject: [PATCH] Translation template generator first draft --- ast/abstract/Node.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ast/abstract/Node.lua b/ast/abstract/Node.lua index 17cb758..aa785bb 100644 --- a/ast/abstract/Node.lua +++ b/ast/abstract/Node.lua @@ -156,6 +156,21 @@ Node = class { return t end, + -- generate anselme code that can be used as a base for a translation file + -- will include every translatable element found in this node and its children + -- TODO: generate more stable context than source position, and only add necessery context to the tag + generate_translation_template = function(self) + local l = self:list_translatable() + local r = {} + for _, tr in ipairs(l) do + table.insert(r, "(("..tr.source.."))") + table.insert(r, Call:new(Identifier:new("_#_"), ArgumentTuple:new(tr.context, Identifier:new("_")))) + table.insert(r, "\t"..Call:new(Identifier:new("_->_"), ArgumentTuple:new(tr, tr)):format()) + table.insert(r, "") + end + return table.concat(r, "\n") + end, + -- call the node with the given arguments -- return result AST -- arg is a ArgumentTuple node (already evaluated)