mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 07:26:02 +01:00
feat(shared/locale): locale phrases
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
local dict
|
local dict = {}
|
||||||
|
|
||||||
---@param str string
|
---@param str string
|
||||||
---@param ... string | number
|
---@param ... string | number
|
||||||
@@ -14,7 +14,7 @@ function locale(str, ...)
|
|||||||
return lstr
|
return lstr
|
||||||
end
|
end
|
||||||
|
|
||||||
return ("Translation for '%s' does not exist"):format(str)
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return { [string]: string }
|
---@return { [string]: string }
|
||||||
@@ -23,8 +23,19 @@ function lib.getLocales()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function lib.loadLocale()
|
function lib.loadLocale()
|
||||||
local JSON = LoadResourceFile(cache.resource, ('locales/%s.json'):format(GetConvar('ox:locale', 'en'))) or LoadResourceFile(cache.resource, 'locales/en.json')
|
local locales = json.decode(LoadResourceFile(cache.resource, ('locales/%s.json'):format(GetConvar('ox:locale', 'en'))) or LoadResourceFile(cache.resource, 'locales/en.json') or '[]')
|
||||||
dict = JSON and json.decode(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
|
end
|
||||||
|
|
||||||
return lib.loadLocale
|
return lib.loadLocale
|
||||||
|
|||||||
Reference in New Issue
Block a user