feat: dynamic localization strings and caching

`t()` now works as `string.format()` → `t('Foo %d %s', 42, 'bar')`
This commit is contained in:
tomasklaen
2023-04-25 10:01:57 +02:00
parent 1947f1b614
commit ec4e51e954

View File

@@ -1,4 +1,5 @@
local locale = {}
local cache = {}
-- https://learn.microsoft.com/en-us/windows/apps/publish/publish-your-app/supported-languages?pivots=store-installer-msix#list-of-supported-languages
function get_languages()
@@ -55,8 +56,11 @@ function make_locale()
end
---@param text string
function t(text)
return locale[text] or text
function t(text, ...)
if not text then return '' end
if cache[text] then return cache[text] end
cache[text] = string.format(locale[text] or text, ...)
return cache[text]
end
locale = make_locale()