Files
ox_lib/imports/locale/shared.lua

29 lines
720 B
Lua
Raw Normal View History

2022-04-29 05:56:41 +10:00
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
function lib.loadLocale(locale)
if not locale then
locale = lib.context == 'server' and lib.getServerLocale() or GetExternalKvpString('ox_lib', 'locale') or 'en'
end
2022-04-29 05:56:41 +10:00
local resourceName = GetCurrentResourceName()
local JSON = LoadResourceFile(resourceName, ('locales/%s.json'):format(locale)) or LoadResourceFile(resourceName, ('locales/en.json'):format(locale))
dict = JSON and json.decode(JSON) or {}
2022-04-29 05:56:41 +10:00
end
AddEventHandler('ox_lib:setLocale', lib.loadLocale)
2022-04-29 05:56:41 +10:00
return lib.loadLocale