feat: dynamic localization strings and caching
`t()` now works as `string.format()` → `t('Foo %d %s', 42, 'bar')`
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
local locale = {}
|
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
|
-- 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()
|
function get_languages()
|
||||||
@@ -55,8 +56,11 @@ function make_locale()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param text string
|
---@param text string
|
||||||
function t(text)
|
function t(text, ...)
|
||||||
return locale[text] or 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
|
end
|
||||||
|
|
||||||
locale = make_locale()
|
locale = make_locale()
|
||||||
|
Reference in New Issue
Block a user