From 9e01be548c02bfe6672586e77e9d5f0ebd7aacb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Sun, 2 Jun 2024 22:22:46 +0200 Subject: [PATCH] [api] add translation template generation function in anselme module --- anselme/init.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/anselme/init.lua b/anselme/init.lua index 27c6234..e53aa50 100644 --- a/anselme/init.lua +++ b/anselme/init.lua @@ -52,7 +52,8 @@ local parser, State -local anselme = { +local anselme +anselme = { --- Global version string. Follow semver. version = "2.0.0-beta2", @@ -78,7 +79,7 @@ local anselme = { parse = function(code, source) return parser(code, source) end, - --- Same as `:parse`, but read the code from a file. + --- Same as `:parse`, but reads the code from a file. -- `source` will be set as the file path. parse_file = function(path) local f = assert(io.open(path, "r")) @@ -86,6 +87,17 @@ local anselme = { f:close() return block end, + --- Generates and return Anselme code (as a string) that can be used as a base for a translation file. + -- This will include every translatable element found in this code. + -- `source` is an optional string; it will be used as the code source name in translation contexts. + generate_translation_template = function(code, source) + return anselme.parse(code, source):generate_translation_template() + end, + --- Same as `:generate_translation_template`, but reads the code from a file. + -- `source` will be set as the file path. + generate_translation_template_file = function(path) + return anselme.parse_file(path):generate_translation_template() + end, --- Return a new [State](#state). new = function() return State:new()