Files
ox_lib/imports/locale/shared.lua
2022-04-29 05:56:41 +10:00

31 lines
642 B
Lua

local dict
function locale(str, ...)
local lstr = dict[str]
if lstr then
if ... then
return lstr and lstr:format(...)
end
return lstr
end
return ("Translation for '%s' does not exist"):format(str)
end
local function loadLocale(locale)
local resourceName = GetCurrentResourceName()
local JSON = LoadResourceFile(resourceName, ('locales/%s.json'):format(locale)) or LoadResourceFile(resourceName, ('locales/en-US.json'):format(locale))
if JSON then
dict = json.decode(JSON)
end
end
AddEventHandler('ox_lib:setLocale', loadLocale)
return function()
loadLocale(GetExternalKvpString('ox_lib', 'locale') or 'en-US')
end