Skip to content

Commit ef26c1e

Browse files
committed
Setup adddition of Resource + Resource as merges
1 parent 8a99b9e commit ef26c1e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

fluent/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ local FluentBundle = class({
1616

1717
add_messages = function (self, input)
1818
if type(input) == "string" then input = { input } end
19-
-- TODO: add way to add two resources together, then reduce instead of unpacking this
20-
local resource = tablex.imap(function (v) return self.syntax:parsestring(v) end, input)
21-
self.locales[self.locale] = resource[1]
19+
local resources = tablex.imap(function (v) return self.syntax:parsestring(v) end, input)
20+
local resource = tablex.reduce('+', resources)
21+
self.locales[self.locale] = resource
2222
end,
2323

2424
format = function (self, identifier, parameters)

fluent/resource.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ local FluentResource = class({
281281
local ast = { type = "Resource", body = {} }
282282
for _, v in ipairs(self.body) do table.insert(ast.body, v:dump_ast()) end
283283
return ast
284+
end,
285+
286+
__add = function (self, resource)
287+
for _, node in ipairs(resource.body) do
288+
self:insert(node)
289+
end
290+
return self
284291
end
285292

286293
})

0 commit comments

Comments
 (0)