mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 23:16:03 +01:00
feature(locale): support nested locales (#463)
This commit is contained in:
@@ -1,6 +1,21 @@
|
|||||||
---@type { [string]: string }
|
---@type { [string]: string }
|
||||||
local dict = {}
|
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 str string
|
||||||
---@param ... string | number
|
---@param ... string | number
|
||||||
---@return string
|
---@return string
|
||||||
@@ -41,7 +56,10 @@ function lib.locale()
|
|||||||
if not locales then return end
|
if not locales then return end
|
||||||
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
|
if type(v) == 'string' then
|
||||||
for var in v:gmatch('${[%w%s%p]-}') do
|
for var in v:gmatch('${[%w%s%p]-}') do
|
||||||
local locale = locales[var:sub(3, -2)]
|
local locale = locales[var:sub(3, -2)]
|
||||||
|
|||||||
Reference in New Issue
Block a user