From 130ea5d17e6e6d04e1bcec359866202eb0b5ed6c Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 19 Jun 2022 13:36:11 +1000 Subject: [PATCH] refactor(init): lib.notify server function Client handler attempts to translate the notification if locales are loaded. --- init.lua | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index e3fccd9..e539ea6 100644 --- a/init.lua +++ b/init.lua @@ -58,6 +58,8 @@ end -- API ----------------------------------------------------------------------------------------------- +local export = exports[ox_lib] + local function call(self, index, ...) local module = rawget(self, index) if not module then @@ -65,7 +67,7 @@ local function call(self, index, ...) if not module then local function method(...) - return exports[ox_lib][index](nil, ...) + return export[index](nil, ...) end if not ... then @@ -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) @@ -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()