mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 09:09:31 +00:00
Move anselme code into its own directory
This commit is contained in:
parent
404e7dd56e
commit
5dd971ff8f
179 changed files with 603 additions and 579 deletions
49
anselme/ast/Translatable.lua
Normal file
49
anselme/ast/Translatable.lua
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
local ast = require("anselme.ast")
|
||||
local TextInterpolation, String
|
||||
|
||||
local operator_priority = require("anselme.common").operator_priority
|
||||
|
||||
local translation_manager
|
||||
|
||||
local Translatable = ast.abstract.Node {
|
||||
type = "translatable",
|
||||
format_priority = operator_priority["%_"],
|
||||
|
||||
expression = nil,
|
||||
|
||||
init = function(self, expression)
|
||||
self.expression = expression
|
||||
self.context = ast.Struct:new()
|
||||
self.context:set(String:new("source"), String:new(self.expression.source))
|
||||
if TextInterpolation:is(self.expression) then
|
||||
self.format_priority = expression.format_priority
|
||||
end
|
||||
end,
|
||||
|
||||
_format = function(self, ...)
|
||||
if TextInterpolation:is(self.expression) then -- wrapped in translatable by default
|
||||
return self.expression:format(...)
|
||||
else
|
||||
return "%"..self.expression:format_right(...)
|
||||
end
|
||||
end,
|
||||
|
||||
traverse = function(self, fn, ...)
|
||||
fn(self.expression, ...)
|
||||
end,
|
||||
|
||||
_eval = function(self, state)
|
||||
return translation_manager:eval(state, self.context, self)
|
||||
end,
|
||||
|
||||
list_translatable = function(self, t)
|
||||
table.insert(t, self)
|
||||
end
|
||||
}
|
||||
|
||||
package.loaded[...] = Translatable
|
||||
TextInterpolation, String = ast.TextInterpolation, ast.String
|
||||
|
||||
translation_manager = require("anselme.state.translation_manager")
|
||||
|
||||
return Translatable
|
||||
Loading…
Add table
Add a link
Reference in a new issue