Skip to content

Commit

Permalink
feat: locales
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed May 13, 2022
1 parent c9ae8b6 commit 29c1ee2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
31 changes: 16 additions & 15 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
lib.locale()

local fuelingCan = nil

AddEventHandler('ox_inventory:currentWeapon', function(currentWeapon)
Expand Down Expand Up @@ -69,7 +71,7 @@ local function createBlip(station)
SetBlipColour(blip, 23)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName('Fuel Station')
AddTextComponentSubstringPlayerName(locale('fuel_station_blip'))
EndTextCommandSetBlipName(blip)
return blip
end
Expand Down Expand Up @@ -163,7 +165,7 @@ local function startFueling(vehicle, isPump)

if 100 - fuel < Config.refillValue then
isFueling = false
return lib.notify({type = 'error', description = 'The tank of this vehicle is full'})
return lib.notify({type = 'error', description = locale('tank_full')})
end

if isPump then
Expand Down Expand Up @@ -238,7 +240,6 @@ local function GetPetrolCan(pumpCoord)

if lib.progressCircle({
duration = Config.petrolCan.duration,
label = 'Fueling can',
useWhileDead = false,
canCancel = true,
disable = {
Expand Down Expand Up @@ -280,20 +281,20 @@ if not Config.qtarget then
if moneyAmount >= Config.petrolCan.price then
GetPetrolCan(nearestPump)
else
lib.notify({type = 'error', description = 'You cannot afford a petrol can'})
lib.notify({type = 'error', description = locale('petrolcan_cannot_afford')})
end
elseif isVehicleCloseEnough(playerCoords, vehicle) then
if moneyAmount >= Config.priceTick then
startFueling(vehicle, true)
else
lib.notify({type = 'error', description = 'You cannot afford to refuel your vehicle'})
lib.notify({type = 'error', description = locale('refuel_cannot_afford')})
end
else
return lib.notify({type = 'error', description = 'Your vehicle is too far away'})
return lib.notify({type = 'error', description = locale('vehicle_far')})
end
else
if not Config.petrolCan.enabled or isFueling or cache.vehicle then return end
if nearestPump then return lib.notify({type = 'error', description = 'Put your can away before fueling with the pump'}) end
if nearestPump then return lib.notify({type = 'error', description = locale('pump_fuel_with_can')}) end

local entityHit, _ = Raycast()
if not entityHit then return end
Expand All @@ -305,7 +306,7 @@ if not Config.qtarget then
if closeToVehicle then
return startFueling(entityHit, false)
else
if i == #bones then return lib.notify({type = 'error', description = 'Your vehicle is too far away'}) end
if i == #bones then return lib.notify({type = 'error', description = locale('vehicle_far')}) end
end
end
end
Expand All @@ -324,7 +325,7 @@ if Config.qtarget then
if ox_inventory:Search(2, 'money') >= Config.priceTick then
startFueling(GetPlayersLastVehicle(), 1)
else
lib.notify({type = 'error', description = 'You cannot afford to refuel your vehicle'})
lib.notify({type = 'error', description = locale('refuel_cannot_afford')})
end
end,
icon = "fas fa-gas-pump",
Expand All @@ -341,11 +342,11 @@ if Config.qtarget then
if ox_inventory:Search(2, 'money') >= Config.petrolCan.price then
GetPetrolCan(GetEntityCoords(entity))
else
lib.notify({type = 'error', description = 'You cannot afford a petrol can'})
lib.notify({type = 'error', description = locale('petrolcan_cannot_afford')})
end
end,
icon = "fas fa-faucet",
label = "Buy or refill a fuel can",
label = locale('petrolcan_buy_or_refill'),
},
},
distance = 2
Expand All @@ -359,7 +360,7 @@ if Config.qtarget then
startFueling(entity)
end,
icon = "fas fa-gas-pump",
label = "Start fueling",
label = locale('start_fueling'),
canInteract = function (entity)
if isFueling or cache.vehicle then
return false
Expand All @@ -372,6 +373,6 @@ if Config.qtarget then
})
end

AddTextEntry('fuelHelpText', 'Press ~INPUT_C2939D45~ to fuel')
AddTextEntry('petrolcanHelpText', 'Press ~INPUT_C2939D45~ to buy or refill a fuel can')
AddTextEntry('fuelLeaveVehicleText', 'Leave the vehicle to be able to start fueling')
AddTextEntry('fuelHelpText', locale('fuel_help'))
AddTextEntry('petrolcanHelpText', locale('petrolcan_help'))
AddTextEntry('fuelLeaveVehicleText', locale('leave_vehicle'))
6 changes: 5 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
}

shared_scripts {
'@ox_lib/init.lua',
'config.lua'
}

Expand All @@ -26,7 +27,10 @@ server_scripts {
}

client_scripts {
'@ox_lib/init.lua',
'data/stations.lua',
'client.lua'
}

files {
'locales/*.json'
}
18 changes: 18 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"tank_full": "The tank of this vehicle is fuill",
"petrolcan_cannot_afford": "You cannot afford a petrol can",
"refuel_cannot_afford": "You cannot afford to refuel your vehicle",
"vehicle_far": "Your vehicle is too far away",
"pump_fuel_with_can": "Put your can away before fueling with the pump",
"fuel_help": "Press ~INPUT_C2939D45~ to fuel",
"petrolcan_help": "Press ~INPUT_C2939D45~ to buy or refill a fuel can",
"leave_vehicle": "Leave the vehicle to be able to start fueling",
"start_fueling": "Start fueling",
"petrolcan_buy_or_refill": "Buy or refill a fuel can",
"fuel_station_blip": "Fuel station",
"not_enough_money": "Not enough money! Missing $%s",
"fuel_success": "Fueled to %s - $%s",
"petrolcan_refill": "Paid $%s for refilling your fuel can",
"petrolcan_buy": "Paid $%s for a fuel can",
"petrolcan_cannot_carry": "You cannot carry this fuel can"
}
12 changes: 7 additions & 5 deletions server.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
lib.locale()

local ox_inventory = exports.ox_inventory

local function isMoneyEnough(money, price)
if money < price then
local missingMoney = price - money
TriggerClientEvent('ox_lib:notify', source, {
type = 'error',
description = ('Not enough money! Missing %s$'):format(missingMoney)
description = locale('not_enough_money', missingMoney)
})
return false
else
Expand All @@ -21,7 +23,7 @@ RegisterNetEvent('ox_fuel:pay', function(price, fuel)
fuel = math.floor(fuel)
TriggerClientEvent('ox_lib:notify', source, {
type = 'success',
description = ('Fueled to ' .. fuel .. '% ' .. '- $' .. price)
description = locale('fuel_success', fuel, price)
})
end)

Expand All @@ -41,7 +43,7 @@ RegisterNetEvent('ox_fuel:fuelCan', function(hasCan, price)
ox_inventory:RemoveItem(source, 'money', price)
TriggerClientEvent('ox_lib:notify', source, {
type = 'success',
description = ('Paid $%s for refilling your fuel can'):format(price)
description = locale('petrolcan_refill', price)
})
end
else
Expand All @@ -53,7 +55,7 @@ RegisterNetEvent('ox_fuel:fuelCan', function(hasCan, price)
if not canCarry then
return TriggerClientEvent('ox_lib:notify', source, {
type = 'error',
description = ('You can\'t carry anymore stuff'):format(missingMoney)
description = locale('petrolcan_cannot_carry')
})
end

Expand All @@ -62,7 +64,7 @@ RegisterNetEvent('ox_fuel:fuelCan', function(hasCan, price)
ox_inventory:RemoveItem(source, 'money', price)
TriggerClientEvent('ox_lib:notify', source, {
type = 'success',
description = ('Paid $%s for buying a fuel can'):format(price)
description = locale('petrolcan_buy', price)
})
else
-- manually triggered event, cheating?
Expand Down

0 comments on commit 29c1ee2

Please sign in to comment.