Skip to content

Commit

Permalink
Add language support
Browse files Browse the repository at this point in the history
  • Loading branch information
Giana committed Jan 27, 2023
1 parent 5055221 commit 19ac863
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
26 changes: 13 additions & 13 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local function getDisplayHeaderMenu()
local headerMenu = {
{
header = Config.Label,
txt = 'View bicycles for rent',
txt = Lang:t('menu.view_bicycles'),
params = {
event = 'qb-bikerental:client:openBikeMenu'
}
Expand Down Expand Up @@ -102,7 +102,7 @@ RegisterNetEvent('qb-bikerental:client:openBikeMenu', function()
table.sort(ordered_keys)
local bikeMenu = {
{
header = "Bicycles for Rent",
header = Lang:t('menu.bicycles_rent'),
isMenuHeader = true
}
}
Expand All @@ -111,7 +111,7 @@ RegisterNetEvent('qb-bikerental:client:openBikeMenu', function()
if v.available then
bikeMenu[#bikeMenu + 1] = {
header = v.label,
txt = 'To Rent: $' .. v.rental_cost .. '',
txt = Lang:t('menu.to_rent', {cost = v.rental_cost}),
params = {
isServer = true,
event = 'qb-bikerental:server:swapVehicle',
Expand All @@ -123,7 +123,7 @@ RegisterNetEvent('qb-bikerental:client:openBikeMenu', function()
end
end
bikeMenu[#bikeMenu + 1] = {
header = 'Cancel',
header = Lang:t('menu.cancel'),
params = {
event = 'qb-menu:client:closeMenu'
}
Expand Down Expand Up @@ -155,7 +155,7 @@ RegisterNetEvent('qb-bikerental:client:swapVehicle', function(data)
--SetEntityHeading(newVeh, displaySpot.rental_coords.w)
SetVehicleDoorsLocked(newVeh, 3)
FreezeEntityPosition(newVeh, true)
SetVehicleNumberPlateText(newVeh, 'RENT ME')
SetVehicleNumberPlateText(newVeh, Lang:t('other.plate_text'))
Config.RentalLocations[Closest_Display].chosen_veh = model
end
end)
Expand All @@ -164,21 +164,21 @@ RegisterNetEvent('qb-bikerental:client:openBikeRentalConfirmationMenu', function
local bike = data.vehicle
local menu = {
{
header = 'Is this the bicycle you want to rent?',
header = Lang:t('menu.rent_confirm'),
isMenuHeader = true
},
{
header = bike.label .. '',
txt = 'To Rent: $' .. bike.rental_cost .. ''
header = bike.label,
txt = Lang:t('menu.to_rent', {cost = bike.rental_cost})
},
{
header = 'No, take me back!',
header = Lang:t('menu.no_back'),
params = {
event = 'qb-bikerental:client:openBikeMenu'
}
},
{
header = 'Yes, please!',
header = Lang:t('menu.yes_please'),
params = {
event = 'qb-bikerental:client:RentBike',
args = {
Expand Down Expand Up @@ -207,7 +207,7 @@ RegisterNetEvent('qb-bikerental:client:RentBike', function(data)
TriggerEvent("vehiclekeys:client:SetOwner", GetVehicleNumberPlateText(ent))
end)
else
QBCore.Functions.Notify("You don't have enough money!")
QBCore.Functions.Notify(Lang:t('error.not_enough_money'))
end
end, cost)
end)
Expand All @@ -232,7 +232,7 @@ Citizen.CreateThread(function()
SetVehicleDoorsLocked(veh, 3)
--SetEntityHeading(veh, v.rental_coords.w)
FreezeEntityPosition(veh, true)
SetVehicleNumberPlateText(veh, 'RENT ME')
SetVehicleNumberPlateText(veh, Lang:t('other.plate_text'))
configureBlip(v)
end
end
Expand All @@ -252,7 +252,7 @@ Citizen.CreateThread(function()
if dist < 12 then
DrawMarker(2, v.rental_coords.x, v.rental_coords.y, v.rental_coords.z + 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.1, 109, 255, 0, 0.64, 0, 0, 0, 1, 0, 0, 0)
if not Config.WalkUpRentalMenu and dist < 2 then
DrawText3Ds(v.rental_coords.x, v.rental_coords.y, v.rental_coords.z + 0.9, '~g~E~w~ - View Bicycles for Rent')
DrawText3Ds(v.rental_coords.x, v.rental_coords.y, v.rental_coords.z + 0.9, Lang:t('button.view_bicycles'))
if IsControlJustPressed(0, 38) then
setClosestDisplay()
TriggerEvent('qb-bikerental:client:openBikeMenu')
Expand Down
6 changes: 5 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ game 'gta5'
author 'Giana - github.com/Giana'
description 'g-bikerentals'

shared_script 'config.lua'
shared_scripts {
'@qb-core/shared/locale.lua',
'locales/en.lua',
'config.lua',
}

client_scripts {
'@PolyZone/client.lua',
Expand Down
28 changes: 28 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
local Translations = {
error = {
not_enough_money = 'You do not have enough money!'
},
menu = {
view_bicycles = 'View bicycles for rent',
bicycles_rent = 'Bicycles for Rent',
to_rent = 'To Rent: $%{cost}',
cancel = 'Cancel',
rent_confirm = 'Is this the bicycle you want to rent?',
no_back = 'No, take me back!',
yes_please = 'Yes, please!'
},
button = {
view_bicycles = '~g~E~w~ - View Bicycles for Rent'
},
other = {
plate_text = 'RENT ME',
purchase_desc = 'Bike rental'
}
}

-- other.purchase_desc

Lang = Locale:new({
phrases = Translations,
warnOnMissing = true
})
4 changes: 2 additions & 2 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ end)
QBCore.Functions.CreateCallback('qb-bikerental:server:CanRentBike', function(source, cb, rentalCost)
local player = QBCore.Functions.GetPlayer(source)
if player.Functions.GetMoney('cash') >= rentalCost then
player.Functions.RemoveMoney('cash', rentalCost, 'Bike rental')
player.Functions.RemoveMoney('cash', rentalCost, Lang:t('other.purchase_desc'))
cb(true)
elseif player.Functions.GetMoney('bank') >= rentalCost then
player.Functions.RemoveMoney('bank', rentalCost, 'Bike rental')
player.Functions.RemoveMoney('bank', rentalCost, Lang:t('other.purchase_desc'))
cb(true)
else
cb(false)
Expand Down

0 comments on commit 19ac863

Please sign in to comment.