Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Locale #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ CurrentZone = nil
---@type table<string, function>
local componentActions = {}

lib.locale()

---@param componentType string
---@param action function
---@param actionPermissions string[]
Expand All @@ -19,7 +21,7 @@ exports('registerComponentAction', RegisterComponentAction)

RegisterComponentAction('stash', function(component)
return exports.ox_inventory:openInventory('stash', component.name)
end, {'All access'})
end, {locale('all_access')})

local menus = {
contextMenu = {
Expand Down Expand Up @@ -50,6 +52,7 @@ local function setBlipVariables(blip, property)
local variables = PropertyVariables[property]
SetBlipColour(blip, variables.colour)
SetBlipShrink(blip, true)
SetBlipDisplay(blip, 4)

if variables.owner ~= player.charId and not (variables.group and player.groups[variables.group]) then
SetBlipAsShortRange(blip, true)
Expand Down Expand Up @@ -301,14 +304,13 @@ local function isPermitted(property, componentId)
for i = 1, #variables.permissions do
local level = variables.permissions[i]
local access = i == 1 and 1 or level.components[componentId]

if access and (level.everyone or (level.players and level.players[player.charId]) or player.hasGroup(level.groups)) then
return access
end
end
end

lib.notify({title = 'Permission Denied', type = 'error'})
lib.notify({title = locale("permissions_deined"), type = 'error'})
return false
end
exports('isPermitted', isPermitted)
Expand Down
52 changes: 26 additions & 26 deletions client/management.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ RegisterComponentAction('management', function(component)

local property = Properties[component.property]
local variables = PropertyVariables[property.name]
local values = {'Edit Component Access', 'Edit Door Access', 'Edit Members', 'Delete Level'}
local values = {locale("edit_componet_access"), locale("edit_door_acces"), locale("edit_menbers"), locale("delete_level")}
local options = {
{
label = ('Owner: %s'):format(variables.ownerName or 'None'),
description = 'Set Property Owner'
label = locale("owner", variables.ownerName or locale("none")),
description = locale("set_property_owner")
},
{
label = ('Group: %s'):format(variables.groupName or 'None'),
description = 'Set Property Group'
label = locale("group", variables.ownerName or locale("none")),
description = locale("set_property_group")
}
}

for i = 1, #variables.permissions do
options[#options + 1] = {
label = ('Level %s'):format(i),
label = locale("level",i),
values = values
}
end

options[#options + 1] = {
label = 'Create New Level',
label = locale("create_new_level"),
}

return {
Expand All @@ -66,15 +66,15 @@ RegisterComponentAction('management', function(component)

local level = scrollIndex and selected - 2 or #variables.permissions + 1
local permissionLevel = variables.permissions[level]
local title = values[scrollIndex] or 'New Level'
local title = values[scrollIndex] or locale("new_level")

if scrollIndex then
local options = {
{label = ('Save Level %s'):format(level)}
{label = locale("save_level",level)}
}

if level == 1 and scrollIndex ~= 3 then
lib.notify({title = 'Action not possible for this permission level', type = 'error'})
lib.notify({title =locale("action_not_possible_for_level"), type = 'error'})
lib.showMenu('component_menu')
return
elseif scrollIndex == 1 then
Expand All @@ -85,7 +85,7 @@ RegisterComponentAction('management', function(component)
label = component.name,
values = {'None', table.unpack(Permissions[component.type])},
defaultIndex = permissionLevel.components and permissionLevel.components[i] and permissionLevel.components[i] + 1 or 1,
description = ('Type: %s'):format(component.type:gsub('^%l', string.upper)),
description = locale("type", component.type:gsub('^%l', string.upper)),
close = false,
args = {
section = 'components',
Expand All @@ -109,7 +109,7 @@ RegisterComponentAction('management', function(component)
end
elseif scrollIndex == 3 then
options[#options + 1] = {
label = 'Everyone',
label = locale("everyone"),
checked = permissionLevel.everyone or false,
close = false,
args = {section = 'everyone'}
Expand Down Expand Up @@ -145,8 +145,8 @@ RegisterComponentAction('management', function(component)
end
elseif scrollIndex == 4 then
local delete = lib.alertDialog({
header = 'Please Confirm',
content = 'Are you sure you want to delete this permission level?',
header = locale("please_confirm"),
content = locale("are_you_sure_delete_permission_level"),
centered = true,
cancel = true
})
Expand Down Expand Up @@ -228,14 +228,14 @@ RegisterComponentAction('management', function(component)

lib.registerMenu({
id = 'set_property_value',
title = ('Set Property %s'):format(value:gsub('^%l', string.upper)),
title = locale("set_property",value:gsub('^%l', string.upper)),
options = options,
onClose = onClose
},
function(selected, scrollIndex, args)
local setValue = lib.alertDialog({
header = 'Please Confirm',
content = ('Are you sure you want to set the property %s to %s'):format(value, args.label),
header = locale("please_confirm"),
content = locale("are_you_sure_set_property", value, args.label),
centered = true,
cancel = true
})
Expand All @@ -257,15 +257,15 @@ RegisterComponentAction('management', function(component)
lib.showMenu('set_property_value')
else
local options = {
{label = ('Continue Level %s'):format(level)}
{label = locale("continue_level", level)}
}
for i = 1, #property.components do
local component = property.components[i]

options[#options + 1] = {
label = component.name,
values = {'None', table.unpack(Permissions[component.type])},
description = ('Type: %s'):format(component.type:gsub('^%l', string.upper)),
description = locale("type", component.type:gsub('^%l', string.upper)),
close = false,
args = {
section = 'components',
Expand All @@ -276,14 +276,14 @@ RegisterComponentAction('management', function(component)

lib.registerMenu({
id = 'new_level_components',
title = 'Set Component Access',
title = locale("set_component_access"),
options = options,
onSideScroll = updatePermissionData,
onClose = onClose
},
function(selected, scrollIndex, args)
local options = {
{label = ('Continue Level %s'):format(level)}
{label = locale("continue_level", level)}
}
for i = 1, #displayData.doors do
local door = displayData.doors[i]
Expand All @@ -301,19 +301,19 @@ RegisterComponentAction('management', function(component)

lib.registerMenu({
id = 'new_level_doors',
title = 'Set Door Access',
title = locale("set_door_access"),
options = options,
onSideScroll = updatePermissionData,
onCheck = updatePermissionData,
onClose = onClose
},
function(selected, scrollIndex, args)
local options = {
{label = ('Finish Level %s'):format(level)}
{label = locale ("finish_level", level)}
}

options[#options + 1] = {
label = 'Everyone',
label = locale("everyone"),
checked = false,
close = false,
args = {section = 'everyone'}
Expand Down Expand Up @@ -349,7 +349,7 @@ RegisterComponentAction('management', function(component)

lib.registerMenu({
id = 'new_level_members',
title = 'Set Members',
title = locale("set_members"),
options = options,
onSideScroll = updatePermissionData,
onCheck = updatePermissionData,
Expand Down Expand Up @@ -378,6 +378,6 @@ RegisterComponentAction('management', function(component)
end
end
}, 'listMenu'
end, {'All access'})
end, {locale('all_access')})

RegisterMenu({'edit_level', 'set_property_value', 'new_level_components', 'new_level_doors', 'new_level_members'}, 'listMenu')
44 changes: 22 additions & 22 deletions client/parking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local function manageVehicle(data)
}
},
{
title = 'Update Values',
title = locale("update_values"),
disabled = data.vehicle.owner ~= player.charId,
onSelect = function(args)
local groupTable = player.groups
Expand All @@ -34,18 +34,18 @@ local function manageVehicle(data)
local options = {
{
type = 'input',
label = 'Label',
label = locale("label_label"),
default = data.vehicle.label
},
{
type = 'select',
label = 'Group',
label = locale("label_group"),
default = data.vehicle.group,
options = groups
}
}

local input = lib.inputDialog('Update Vehicle Values', options)
local input = lib.inputDialog(locale("update_vehicle_values"), options)

if input then
if not data.vehicle.label and input[1] == "" then input[1] = nil end
Expand All @@ -72,14 +72,13 @@ local function manageVehicle(data)
end,
},
{
title = 'Retrieve',
title = locale("retrive"),
onSelect = function(args)
local response, msg = lib.callback.await('ox_property:parking', 100, 'retrieve_vehicle', {
property = data.component.property,
componentId = data.component.componentId,
id = data.vehicle.id
})

if msg then
lib.notify({title = msg, type = response and 'success' or 'error'})
end
Expand All @@ -89,7 +88,7 @@ local function manageVehicle(data)

lib.registerContext({
id = 'manage_vehicle',
title = 'Manage Vehicle',
title = locale("manage_vehicle"),
menu = 'vehicle_list',
options = options
})
Expand All @@ -112,15 +111,16 @@ local function vehicleList(data)
['Location'] = vehicle.location
},
onSelect = function(args)
if args.action == 'Manage' then
if args.action == locale("manage") then
manageVehicle({component = data.component, vehicle = vehicle})
else
local response, msg = lib.callback.await('ox_property:parking', 100, args.action == 'Retrieve' and 'retrieve_vehicle' or 'move_vehicle', {
print(json.encode(args,{indent=true}))
local response, msg = lib.callback.await('ox_property:parking', 100, args.action == locale('retrive') and 'retrieve_vehicle' or 'move_vehicle', {
property = data.component.property,
componentId = data.component.componentId,
id = args.id
})

if msg then
lib.notify({title = msg, type = response and 'success' or 'error'})
end
Expand All @@ -135,7 +135,7 @@ local function vehicleList(data)

lib.registerContext({
id = 'vehicle_list',
title = data.componentOnly and ('%s - %s - Vehicles'):format(Properties[data.component.property].label, data.component.name) or 'All Vehicles',
title = data.componentOnly and locale("vehicle_list", Properties[data.component.property].label, data.component.name) or locale("all_vehicles"),
menu = 'component_menu',
options = options
})
Expand All @@ -157,7 +157,7 @@ RegisterComponentAction('parking', function(component)

if cache.seat == -1 then
options[#options + 1] = {
title = 'Store Vehicle',
title = locale("store_vehicle"),
onSelect = function()
if cache.seat == -1 then
local response, msg = lib.callback.await('ox_property:parking', 100, 'store_vehicle', {
Expand All @@ -170,7 +170,7 @@ RegisterComponentAction('parking', function(component)
lib.notify({title = msg, type = response and 'success' or 'error'})
end
else
lib.notify({title = "You are not in the driver's seat", type = 'error'})
lib.notify({title = locale("are_you_not_driver_seat"), type = 'error'})
end
end
}
Expand All @@ -182,13 +182,13 @@ RegisterComponentAction('parking', function(component)
for i = 1, len do
local vehicle = vehicles[i]
vehicle.name = vehicleNames[vehicle.model]
vehicle.location = 'Unknown'
vehicle.action = 'Recover'
vehicle.location = locale("unknown")
vehicle.action = locale("recover")

if vehicle.stored and vehicle.stored:find(':') then
if vehicle.stored == currentComponent then
vehicle.location = 'Current location'
vehicle.action = vehicle.owner == player.charId and 'Manage' or 'Retrieve'
vehicle.location = locale("current_location")
vehicle.action = vehicle.owner == player.charId and locale("manage") or locale("retrive")
componentVehicles[#componentVehicles + 1] = vehicle
else
local propertyName, componentId = string.strsplit(':', vehicle.stored)
Expand All @@ -204,8 +204,8 @@ RegisterComponentAction('parking', function(component)
end

options[#options + 1] = {
title = 'Open Location',
description = 'View your vehicles at this location',
title = locale("open_location"),
description = locale("view_vehicles_at_location"),
metadata = {['Vehicles'] = #componentVehicles},
onSelect = #componentVehicles > 0 and vehicleList,
args = {
Expand All @@ -216,8 +216,8 @@ RegisterComponentAction('parking', function(component)
}

options[#options + 1] = {
title = 'All Vehicles',
description = 'View all your vehicles',
title = locale("all_vehicles"),
description = locale("view_all_vehicles"),
metadata = {['Vehicles'] = len},
onSelect = len > 0 and vehicleList,
args = {
Expand All @@ -227,7 +227,7 @@ RegisterComponentAction('parking', function(component)
}

return {options = options}, 'contextMenu'
end, {'All access'})
end, {locale('all_access')})

RegisterMenu({'vehicle_list', 'manage_vehicle'}, 'contextMenu')

Expand Down
Loading