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
|
|
|
|
|
|
|
|
|
|
local function loadLocale(locale)
|
|
|
|
|
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-04-29 05:56:41 +10:00
|
|
|
|
|
|
|
|
if JSON then
|
|
|
|
|
dict = json.decode(JSON)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
AddEventHandler('ox_lib:setLocale', loadLocale)
|
|
|
|
|
|
|
|
|
|
return function()
|
2022-04-30 05:04:15 +10:00
|
|
|
local lang = IsDuplicityVersion() and lib.getServerLocale() or GetExternalKvpString('ox_lib', 'locale') or 'en'
|
2022-04-29 16:53:24 +10:00
|
|
|
loadLocale(lang)
|
2022-04-29 05:56:41 +10:00
|
|
|
end
|