From 834c95f0dedf522909394c9a6d0d803402cd541f Mon Sep 17 00:00:00 2001 From: bicatcho11 <151503460+bicatcho11@users.noreply.github.com> Date: Sun, 25 Feb 2024 14:57:07 +0300 Subject: [PATCH] feat: ox_lib locales (#77) * add locale * Create en.json * Update consumables.lua * Update cruise.lua * Update editor.lua * Update en.json --- client/consumables.lua | 36 ++++++++++++++++++------------------ client/cruise.lua | 8 ++++---- client/editor.lua | 8 ++++---- fxmanifest.lua | 7 +++++-- locales/en.json | 29 +++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 28 deletions(-) create mode 100644 locales/en.json diff --git a/client/consumables.lua b/client/consumables.lua index 43695be..d835dbe 100644 --- a/client/consumables.lua +++ b/client/consumables.lua @@ -141,7 +141,7 @@ lib.callback.register('consumables:client:Eat', function(itemName) local item = sharedConfig.consumables.food[itemName] if lib.progressBar({ duration = 5000, - label = 'Eating...', + label = locale('progress.eating'), useWhileDead = false, canCancel = true, disable = { @@ -167,7 +167,7 @@ lib.callback.register('consumables:client:Eat', function(itemName) TriggerServerEvent('hud:server:RelieveStress', math.random(item.stressRelief.min, item.stressRelief.max)) return true else -- if canceled - exports.qbx_core:Notify('Canceled...', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') return false end end) @@ -176,7 +176,7 @@ lib.callback.register('consumables:client:Drink', function(itemName) local item = sharedConfig.consumables.drink[itemName] if lib.progressBar({ duration = 5000, - label = 'Drinking...', + label = locale('progress.drinking'), useWhileDead = false, canCancel = true, disable = { @@ -202,7 +202,7 @@ lib.callback.register('consumables:client:Drink', function(itemName) TriggerServerEvent('hud:server:RelieveStress', math.random(item.stressRelief.min, item.stressRelief.max)) return true else -- if canceled - exports.qbx_core:Notify('Canceled...', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') return false end end) @@ -211,7 +211,7 @@ lib.callback.register('consumables:client:DrinkAlcohol', function(itemName) local item = sharedConfig.consumables.alcohol[itemName] if lib.progressBar({ duration = math.random(3000, 6000), - label = 'Drinking liquor...', + label = locale('progress.drinking_liquor'), useWhileDead = false, canCancel = true, disable = { @@ -243,7 +243,7 @@ lib.callback.register('consumables:client:DrinkAlcohol', function(itemName) end return true else -- if canceled - exports.qbx_core:Notify('Canceled...', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') return false end end) @@ -251,7 +251,7 @@ end) RegisterNetEvent('consumables:client:Cokebaggy', function() if lib.progressBar({ duration = math.random(5000, 8000), - label = 'Quick sniff...', + label = locale('progress.popping_pills'), useWhileDead = false, canCancel = true, disable = { @@ -272,14 +272,14 @@ RegisterNetEvent('consumables:client:Cokebaggy', function() TriggerEvent('evidence:client:SetStatus', 'widepupils', 200) cokeBaggyEffect() else -- if canceled - exports.qbx_core:Notify('Canceled...', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') end end) RegisterNetEvent('consumables:client:Crackbaggy', function() if lib.progressBar({ duration = math.random(7000, 10000), - label = 'Smoking crack...', + label = locale('progress.smoking_crack'), useWhileDead = false, canCancel = true, disable = { @@ -300,14 +300,14 @@ RegisterNetEvent('consumables:client:Crackbaggy', function() TriggerEvent('evidence:client:SetStatus', 'widepupils', 300) crackBaggyEffect() else -- if canceled - exports.qbx_core:Notify('Canceled...', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') end end) RegisterNetEvent('consumables:client:EcstasyBaggy', function() if lib.progressBar({ duration = 3000, - label = 'Popping pills...', + label = locale('progress.popping_pills'), useWhileDead = false, canCancel = true, disable = { @@ -327,14 +327,14 @@ RegisterNetEvent('consumables:client:EcstasyBaggy', function() ecstasyEffect() else -- if canceled - exports.qbx_core:Notify('Canceled...', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') end end) RegisterNetEvent('consumables:client:oxy', function() if lib.progressBar({ duration = 2000, - label = 'Healing...', + label = locale('progress.healing'), useWhileDead = false, canCancel = true, disable = { @@ -355,14 +355,14 @@ RegisterNetEvent('consumables:client:oxy', function() ClearPedBloodDamage(cache.ped) healOxy() else -- if canceled - exports.qbx_core:Notify('Canceled', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') end end) RegisterNetEvent('consumables:client:meth', function() if lib.progressBar({ duration = 1500, - label = 'Smoking meth...', + label = locale('progress.smoking_meth'), useWhileDead = false, canCancel = true, disable = { @@ -384,14 +384,14 @@ RegisterNetEvent('consumables:client:meth', function() TriggerEvent('evidence:client:SetStatus', 'agitated', 300) methBagEffect() else -- if canceled - exports.qbx_core:Notify('Canceled...', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') end end) RegisterNetEvent('consumables:client:UseJoint', function() if lib.progressBar({ duration = 1500, - label = 'Lighting joint...', + label = locale('progress.lighting_joint'), useWhileDead = false, canCancel = true, disable = { @@ -408,7 +408,7 @@ RegisterNetEvent('consumables:client:UseJoint', function() TriggerEvent('evidence:client:SetStatus', 'weedsmell', 300) smokeWeed() else -- if canceled - exports.qbx_core:Notify('Canceled...', 'error') + exports.qbx_core:Notify(locale('error.canceled'), 'error') end end) diff --git a/client/cruise.lua b/client/cruise.lua index c8c6300..5809124 100644 --- a/client/cruise.lua +++ b/client/cruise.lua @@ -31,7 +31,7 @@ local function TriggerCruiseControl() if cruisedSpeed > 0 and GetVehicleCurrentGear(cache.vehicle) > 0 then TriggerEvent('seatbelt:client:ToggleCruise') - exports.qbx_core:Notify('Cruise control enabled!', 'success') + exports.qbx_core:Notify(locale('success.cruise_control_enabled'), 'success') CreateThread(function() while cruisedSpeed > 0 and cache.vehicle do @@ -42,7 +42,7 @@ local function TriggerCruiseControl() if not turningOrBraking and speed < (cruisedSpeed - 1.5) then cruisedSpeed = 0 TriggerEvent('seatbelt:client:ToggleCruise') - exports.qbx_core:Notify('Cruise control disabled!', 'error') + exports.qbx_core:Notify(locale('error.cruise_control_disabled'), 'error') Wait(500) break end @@ -59,7 +59,7 @@ local function TriggerCruiseControl() if IsControlJustPressed(2, 72) then cruisedSpeed = 0 TriggerEvent('seatbelt:client:ToggleCruise') - exports.qbx_core:Notify('Cruise control disabled!', 'error') + exports.qbx_core:Notify(locale('error.cruise_control_disabled'), 'error') Wait(500) break end @@ -76,7 +76,7 @@ RegisterCommand('togglecruise', function() if vehicleClasses[vehicleClass] then TriggerCruiseControl() else - exports.qbx_core:Notify('Cruise control unavailable', 'error') + exports.qbx_core:Notify(locale('error.cruise_control_unavailable'), 'error') end end end, false) diff --git a/client/editor.lua b/client/editor.lua index fa70746..ef77b82 100644 --- a/client/editor.lua +++ b/client/editor.lua @@ -14,7 +14,7 @@ if not shouldAllow then return end RegisterCommand('record', function() StartRecording(1) - TriggerEvent('QBCore:Notify', 'Started Recording!', 'success') + exports.qbx_core:Notify(locale('success.started_recording'), 'success') end, false) RegisterCommand('clip', function() @@ -23,16 +23,16 @@ end, false) RegisterCommand('saveclip', function() StopRecordingAndSaveClip() - TriggerEvent('QBCore:Notify', 'Saved Recording!', 'success') + exports.qbx_core:Notify(locale('success.saved_recording'), 'success') end, false) RegisterCommand('delclip', function() StopRecordingAndDiscardClip() - TriggerEvent('QBCore:Notify', 'Deleted Recording!', 'error') + exports.qbx_core:Notify(locale('error.deleted_recording'), 'error') end, false) RegisterCommand('editor', function() NetworkSessionLeaveSinglePlayer() ActivateRockstarEditor() - TriggerEvent('QBCore:Notify', 'Later aligator!', 'error') + exports.qbx_core:Notify(locale('error.later_aligator'), 'error') end, false) diff --git a/fxmanifest.lua b/fxmanifest.lua index 9d63137..a434972 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -5,6 +5,8 @@ description 'Collection of small scripts' repository 'https://github.com/Qbox-project/qbx_smallresources' version '1.1.0' +ox_lib 'locale' + shared_scripts { '@ox_lib/init.lua', '@qbx_core/modules/lib.lua', @@ -18,8 +20,9 @@ client_scripts { server_script 'server/*.lua' files { - 'config/client.lua', - 'config/shared.lua' + 'locales/*.json', + 'config/client.lua', + 'config/shared.lua' } lua54 'yes' diff --git a/locales/en.json b/locales/en.json new file mode 100644 index 0000000..8ceb6e8 --- /dev/null +++ b/locales/en.json @@ -0,0 +1,29 @@ +{ + "error": { + "canceled": "Canceled..", + "cruise_control_disabled": "Cruise control disabled", + "cruise_control_unavailable": "Cruise control unavailable", + "deleted_recording": "Deleted Recording!", + "later_aligator": "Later aligator!" + }, + "success": { + "cruise_control_enabled": "Cruise control enabled", + "started_recording": "Started Recording!", + "saved_recording": "Saved Recording!" + }, + "progress": { + "eating": "Eating..", + "drinking": "Drinking..", + "drinking_liquor": "Drinking liquor..", + "quick_sniff": "Quick sniff..", + "smoking_crack": "Smoking crack..", + "popping_pills": "Popping pills..", + "healing": "Healing..", + "smoking_meth": "Smoking meth..", + "lighting_joint": "Lighting joint.." + }, + "info": { + "minutes": "minutes", + "seconds": "seconds.." + } +}