mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
[api] add translation template generation function in anselme module
This commit is contained in:
parent
82d2555a7d
commit
9e01be548c
1 changed files with 14 additions and 2 deletions
|
|
@ -52,7 +52,8 @@
|
||||||
|
|
||||||
local parser, State
|
local parser, State
|
||||||
|
|
||||||
local anselme = {
|
local anselme
|
||||||
|
anselme = {
|
||||||
--- Global version string. Follow semver.
|
--- Global version string. Follow semver.
|
||||||
version = "2.0.0-beta2",
|
version = "2.0.0-beta2",
|
||||||
|
|
||||||
|
|
@ -78,7 +79,7 @@ local anselme = {
|
||||||
parse = function(code, source)
|
parse = function(code, source)
|
||||||
return parser(code, source)
|
return parser(code, source)
|
||||||
end,
|
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.
|
-- `source` will be set as the file path.
|
||||||
parse_file = function(path)
|
parse_file = function(path)
|
||||||
local f = assert(io.open(path, "r"))
|
local f = assert(io.open(path, "r"))
|
||||||
|
|
@ -86,6 +87,17 @@ local anselme = {
|
||||||
f:close()
|
f:close()
|
||||||
return block
|
return block
|
||||||
end,
|
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).
|
--- Return a new [State](#state).
|
||||||
new = function()
|
new = function()
|
||||||
return State:new()
|
return State:new()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue