Skip to content

Commit 3c7413f

Browse files
committed
Handle basic parameter substitution
1 parent 8dbf2ca commit 3c7413f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

fluent/resource.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ node_types.Placeable = class({
172172
self.expression = node_to_type(node.expression[1])
173173
end
174174
end,
175-
format = function (self)
176-
return self.expression.value
175+
format = function (self, parameters)
176+
return self.expression:format(parameters)
177177
end
178178
})
179179

@@ -206,6 +206,16 @@ node_types.NumberLiteral = class({
206206
})
207207

208208
node_types.VariableReference = class({
209+
_base = FluentNode,
210+
_init = function (self, node)
211+
self:super(node)
212+
end,
213+
format = function (self, parameters)
214+
return parameters[self.id.name]
215+
end
216+
})
217+
218+
node_types.MessageReference = class({
209219
_base = FluentNode,
210220
_init = function (self, node)
211221
self:super(node)

spec/fluent_spec.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ describe('fluent.bundle', function ()
3434
assert.same("bar baz quz -3.14", en:format("foo"))
3535
end)
3636

37+
it('should parse and format a variable substitution', function ()
38+
local en = FluentBundle("en-US")
39+
en:add_messages('foo = bar { $baz }')
40+
assert.same("bar qux", en:format("foo", { baz = "qux" }))
41+
end)
42+
3743
it('should keep locale instances separate', function ()
3844
local en = FluentBundle("en-US")
3945
local tr = FluentBundle("tr-TR")

0 commit comments

Comments
 (0)