feat(shared/locale): locale phrases

This commit is contained in:
Linden
2023-01-08 15:24:36 +11:00
parent 6bfd6091d7
commit fd5bd066ab

View File

@@ -1,4 +1,4 @@
local dict
local dict = {}
---@param str string
---@param ... string | number
@@ -14,7 +14,7 @@ function locale(str, ...)
return lstr
end
return ("Translation for '%s' does not exist"):format(str)
return str
end
---@return { [string]: string }
@@ -23,8 +23,19 @@ function lib.getLocales()
end
function lib.loadLocale()
local JSON = LoadResourceFile(cache.resource, ('locales/%s.json'):format(GetConvar('ox:locale', 'en'))) or LoadResourceFile(cache.resource, 'locales/en.json')
dict = JSON and json.decode(JSON) or {}
local locales = json.decode(LoadResourceFile(cache.resource, ('locales/%s.json'):format(GetConvar('ox:locale', 'en'))) or LoadResourceFile(cache.resource, 'locales/en.json') or '[]')
for k, v in pairs(locales) do
for var in v:gmatch('${[%w%s%p]-}') do
local locale = locales[var:sub(3, -2)]
if locale then
v = v:gsub(var, locale:gsub('%%', '%%%%'))
end
end
dict[k] = v
end
end
return lib.loadLocale