1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Translation template generator first draft

This commit is contained in:
Étienne Fildadut 2023-12-28 14:28:59 +01:00
parent 91e1311560
commit 507dd5930e

View file

@ -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)