Skip to content

Commit

Permalink
refactor(init): lib.notify server function
Browse files Browse the repository at this point in the history
Client handler attempts to translate the notification if locales are loaded.
  • Loading branch information
thelindat committed Jun 19, 2022
1 parent e95ae85 commit 130ea5d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ end
-- API
-----------------------------------------------------------------------------------------------

local export = exports[ox_lib]

local function call(self, index, ...)
local module = rawget(self, index)
if not module then
module = loadModule(self, index)

if not module then
local function method(...)
return exports[ox_lib][index](nil, ...)
return export[index](nil, ...)
end

if not ... then
Expand Down Expand Up @@ -147,7 +149,7 @@ local ox = GetResourceState('ox_core') ~= 'missing' and setmetatable({}, {

local _cache = setmetatable({}, {
__index = function(self, key)
return rawset(self, key, exports[ox_lib].cache(nil, key) or false)[key]
return rawset(self, key, export.cache(nil, key) or false)[key]
end,

__call = function(self)
Expand All @@ -172,8 +174,28 @@ cache = setmetatable({
})

if service == 'client' then
RegisterNetEvent(('%s:notify'):format(cache.resource), function(data)
if locale then
if data.title then
data.title = locale(data.title) or data.title
end

if data.description then
data.description = locale(data.description) or data.description
end
end

return export:notify(data)
end)

cache.playerId = PlayerId()
cache.serverId = GetPlayerServerId(cache.playerId)
else
local notify = ('%s:notify'):format(cache.resource)

function lib.notify(source, data)
TriggerClientEvent(notify, source, data)
end
end

Citizen.CreateThreadNow(function()
Expand Down

0 comments on commit 130ea5d

Please sign in to comment.