mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(shared/locale): locale phrases
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user