feature(locale): support nested locales (#463)

This commit is contained in:
Armands Vilciņš
2023-12-06 22:44:50 +02:00
committed by GitHub
parent 79e5adda7c
commit 2aeade72f0

View File

@@ -1,6 +1,21 @@
---@type { [string]: string }
local dict = {}
---@param prefix string|nil
---@param source { [string]: string }
---@param target { [string]: string }
local function flattenDict(prefix, source, target)
for key, value in pairs(source) do
local fullKey = prefix and (prefix .. "." .. key) or key
if type(value) == "table" then
flattenDict(fullKey, value, target)
else
target[fullKey] = value
end
end
end
---@param str string
---@param ... string | number
---@return string
@@ -41,7 +56,10 @@ function lib.locale()
if not locales then return end
end
for k, v in pairs(locales) do
local flattenedDict = {}
flattenDict(nil, locales, flattenedDict)
for k, v in pairs(flattenedDict) do
if type(v) == 'string' then
for var in v:gmatch('${[%w%s%p]-}') do
local locale = locales[var:sub(3, -2)]