From 29c1ee2de0f292e57b5a5c6056d2e7a37137b9e1 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 13 May 2022 19:44:57 +0200 Subject: [PATCH] feat: locales --- client.lua | 31 ++++++++++++++++--------------- fxmanifest.lua | 6 +++++- locales/en.json | 18 ++++++++++++++++++ server.lua | 12 +++++++----- 4 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 locales/en.json diff --git a/client.lua b/client.lua index ca01f72..d0df446 100644 --- a/client.lua +++ b/client.lua @@ -1,3 +1,5 @@ +lib.locale() + local fuelingCan = nil AddEventHandler('ox_inventory:currentWeapon', function(currentWeapon) @@ -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 @@ -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 @@ -238,7 +240,6 @@ local function GetPetrolCan(pumpCoord) if lib.progressCircle({ duration = Config.petrolCan.duration, - label = 'Fueling can', useWhileDead = false, canCancel = true, disable = { @@ -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 @@ -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 @@ -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", @@ -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 @@ -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 @@ -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')) diff --git a/fxmanifest.lua b/fxmanifest.lua index 58eb203..54c211e 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -18,6 +18,7 @@ dependencies { } shared_scripts { + '@ox_lib/init.lua', 'config.lua' } @@ -26,7 +27,10 @@ server_scripts { } client_scripts { - '@ox_lib/init.lua', 'data/stations.lua', 'client.lua' +} + +files { + 'locales/*.json' } \ No newline at end of file diff --git a/locales/en.json b/locales/en.json new file mode 100644 index 0000000..2808cc9 --- /dev/null +++ b/locales/en.json @@ -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" +} diff --git a/server.lua b/server.lua index 48ebd88..e3916d1 100644 --- a/server.lua +++ b/server.lua @@ -1,3 +1,5 @@ +lib.locale() + local ox_inventory = exports.ox_inventory local function isMoneyEnough(money, price) @@ -5,7 +7,7 @@ local function isMoneyEnough(money, price) 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 @@ -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) @@ -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 @@ -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 @@ -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?