Skip to content

Commit

Permalink
Interpolate default value
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwinger committed Feb 4, 2022
1 parent 93f8cbe commit 05637a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion i18n/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ function i18n.translate(key, data)
if value then return value end
end

return data.default
if data.default then
return interpolate(data.default, data)
end
end

function i18n.setLocale(newLocale, newPluralizeFunction)
Expand Down
4 changes: 4 additions & 0 deletions spec/i18n_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ describe('i18n', function()
assert.equal('bonjour', i18n('msg', {default='bonjour'}))
end)

it('interpolates the default parameter, if given', function()
assert.equal('bonjour world', i18n('msg', {default='bonjour %{who}', who="world"}))
end)

end)

describe('when there is a count-type translation', function()
Expand Down

0 comments on commit 05637a8

Please sign in to comment.