Skip to content

Commit

Permalink
refactor(locale): server locales
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon committed Jan 19, 2024
1 parent 80a949f commit 8cffdc7
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 116 deletions.
2 changes: 1 addition & 1 deletion server/character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ end)
RegisterNetEvent('qbx_core:server:deleteCharacter', function(citizenId)
local src = source
DeleteCharacter(src, citizenId)
Notify(src, Lang:t('success.character_deleted'), 'success')
Notify(src, locale('success.character_deleted'), 'success')
end)
176 changes: 88 additions & 88 deletions server/commands.lua

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ AddEventHandler('playerJoining', function()
if not serverConfig.checkDuplicateLicense then return end
if usedLicenses[license] then
Wait(0) -- mandatory wait for the drop reason to show up
DropPlayer(src, Lang:t('error.duplicate_license'))
DropPlayer(src, locale('error.duplicate_license'))
else
usedLicenses[license] = true
end
Expand Down Expand Up @@ -76,17 +76,17 @@ local function onPlayerConnecting(name, _, deferrals)
end

if not license then
deferrals.done(Lang:t('error.no_valid_license'))
deferrals.done(locale('error.no_valid_license'))
elseif serverConfig.checkDuplicateLicense and IsLicenseInUse(license) then
deferrals.done(Lang:t('error.duplicate_license'))
deferrals.done(locale('error.duplicate_license'))
end

local databaseTime = os.clock()
local databasePromise = promise.new()

-- conduct database-dependant checks
CreateThread(function()
deferrals.update(string.format(Lang:t('info.checking_ban'), name))
deferrals.update(locale('info.checking_ban', name))
local success, err = pcall(function()
local isBanned, Reason = IsPlayerBanned(src --[[@as Source]])
if isBanned then
Expand All @@ -96,11 +96,11 @@ local function onPlayerConnecting(name, _, deferrals)
end)

if serverConfig.whitelist and success then
deferrals.update(string.format(Lang:t('info.checking_whitelisted'), name))
deferrals.update(string.format(locale('info.checking_whitelisted'), name))
success, err = pcall(function()
if not IsWhitelisted(src --[[@as Source]]) then
Wait(0) -- Mandatory wait
deferrals.done(Lang:t('error.not_whitelisted'))
deferrals.done(locale('error.not_whitelisted'))
end
end)
end
Expand All @@ -113,7 +113,7 @@ local function onPlayerConnecting(name, _, deferrals)

-- wait for database to finish
databasePromise:next(function()
deferrals.update(string.format(Lang:t('info.join_server'), name))
deferrals.update(locale('info.join_server', name))

-- Mandatory wait
Wait(0)
Expand All @@ -124,15 +124,15 @@ local function onPlayerConnecting(name, _, deferrals)
deferrals.done()
end
end, function(err)
deferrals.done(Lang:t('error.connecting_error'))
deferrals.done(locale('error.connecting_error'))
lib.print.error(err)
end)

-- if conducting db checks for too long then raise error
while databasePromise.state == 0 do
if os.clock() - databaseTime > 30 then
deferrals.done(Lang:t('error.connecting_database_timeout'))
error(Lang:t('error.connecting_database_timeout'))
deferrals.done(locale('error.connecting_database_timeout'))
error(locale('error.connecting_database_timeout'))
break
end
Wait(1000)
Expand Down Expand Up @@ -170,7 +170,7 @@ RegisterNetEvent('QBCore:Server:CloseServer', function(reason)
end
end
else
KickWithReason(src, Lang:t("error.no_permission"), nil, nil)
KickWithReason(src, locale("error.no_permission"), nil, nil)
end
end)

Expand All @@ -179,7 +179,7 @@ RegisterNetEvent('QBCore:Server:OpenServer', function()
if HasPermission(src, 'admin') then
serverConfig.closed = false
else
KickWithReason(src, Lang:t("error.no_permission"), nil, nil)
KickWithReason(src, locale("error.no_permission"), nil, nil)
end
end)

Expand All @@ -191,10 +191,10 @@ RegisterNetEvent('QBCore:ToggleDuty', function()
if not player then return end
if player.PlayerData.job.onduty then
player.Functions.SetJobDuty(false)
Notify(src, Lang:t('info.off_duty'))
Notify(src, locale('info.off_duty'))
else
player.Functions.SetJobDuty(true)
Notify(src, Lang:t('info.on_duty'))
Notify(src, locale('info.on_duty'))
end
TriggerClientEvent('QBCore:Client:SetDuty', src, player.PlayerData.job.onduty)
end)
2 changes: 1 addition & 1 deletion server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ local function ExploitBan(playerId, origin)
bannedBy = 'Anti Cheat'
})
end)
DropPlayer(playerId --[[@as string]], Lang:t('info.exploit_banned', {discord = serverConfig.discord}))
DropPlayer(playerId --[[@as string]], locale('info.exploit_banned', serverConfig.discord))
logger.log({
source = 'qbx_core',
webhook = loggingConfig.webhook['anticheat'],
Expand Down
4 changes: 2 additions & 2 deletions server/loops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end)

local function sendPaycheck(player, payment)
player.Functions.AddMoney('bank', payment)
Notify(player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
Notify(player.PlayerData.source, locale('info.received_paycheck', payment))
end

local function pay(player)
Expand All @@ -45,7 +45,7 @@ local function pay(player)
return
end
if account < payment then -- Checks if company has enough money to pay society
Notify(player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
Notify(player.PlayerData.source, locale('error.company_too_poor'), 'error')
return
end
config.removeSocietyMoney(job.name, payment)
Expand Down
2 changes: 2 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
lib.versionCheck('Qbox-project/qbx_core')
if not lib.checkDependency('ox_lib', '3.10.0', true) then error() return end

lib.locale()

---@type 'strict'|'relaxed'|'inactive'
local bucketLockDownMode = GetConvar('qbx:bucketlockdownmode', 'inactive')
SetRoutingBucketEntityLockdownMode(0, bucketLockDownMode)
Expand Down
4 changes: 2 additions & 2 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function LoginV2(source, citizenid, newData)
if playerData and (license2 == playerData.license or license == playerData.license) then
return CheckPlayerData(source, playerData)
else
DropPlayer(tostring(source), Lang:t("info.exploit_dropped"))
DropPlayer(tostring(source), locale("info.exploit_dropped"))
logger.log({
source = 'qbx_core',
webhook = config.logging.webhook['anticheat'],
Expand Down Expand Up @@ -548,7 +548,7 @@ function DeleteCharacter(source, citizenid)
end
end)
else
DropPlayer(tostring(source), Lang:t("info.exploit_dropped"))
DropPlayer(tostring(source), locale("info.exploit_dropped"))
logger.log({
source = 'qbx_core',
webhook = config.logging.webhook['anticheat'],
Expand Down
11 changes: 3 additions & 8 deletions server/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ local function awaitPlayerQueue(source, license, deferrals)
local data = playerDatas[license]

if data and not playerTimingOut then
deferrals.done(Lang:t('error.already_in_queue'))
deferrals.done(locale('error.already_in_queue'))
return
end

Expand All @@ -222,7 +222,7 @@ local function awaitPlayerQueue(source, license, deferrals)
end

if not subQueueIndex then
deferrals.done(Lang:t('error.no_subqueue'))
deferrals.done(locale('error.no_subqueue'))
return
end

Expand All @@ -245,12 +245,7 @@ local function awaitPlayerQueue(source, license, deferrals)
displayTime = displayTime,
}))
else
deferrals.update(Lang:t('info.in_queue', {
queuePos = data.globalPos,
queueSize = totalQueueSize,
subQueue = subQueue.name,
displayTime = displayTime,
}))
deferrals.update(locale('info.in_queue', data.globalPos, totalQueueSize, subQueue.name, displayTime))
end

data.waitingSeconds += 1
Expand Down

0 comments on commit 8cffdc7

Please sign in to comment.