Files
ox_lib/imports/locale/shared.lua
Linden 031cccd886 fix(locale): server hotload and "external" kvp
External kvp's don't exist for the server, so we have to export the proper language.
2022-04-29 16:53:24 +10:00

32 lines
711 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()
local lang = IsDuplicityVersion() and lib.getServerLocale() or GetExternalKvpString('ox_lib', 'locale') or 'en-US'
loadLocale(lang)
end