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