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

feat: locales #5

Merged
merged 1 commit into from
Oct 10, 2023
Merged
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
28 changes: 14 additions & 14 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ local function connectToRadio(channel)
exports["pma-voice"]:setRadioChannel(channel)
local subFreq = string.split(tostring(channel), '.')[2]
if subFreq and subFreq ~= "" then
exports.qbx_core:Notify(Config.messages['joined_to_radio'] ..channel.. ' MHz', 'success')
exports.qbx_core:Notify(Lang:t('joined_radio')..channel..' MHz', 'success')
else
exports.qbx_core:Notify(Config.messages['joined_to_radio'] ..channel.. '.00 MHz', 'success')
exports.qbx_core:Notify(Lang:t('joined_radio')..channel..'.00 MHz', 'success')
end
end

Expand All @@ -33,7 +33,7 @@ local function leaveradio()
onRadio = false
exports["pma-voice"]:setRadioChannel(0)
exports["pma-voice"]:setVoiceProperty("radioEnabled", false)
exports.qbx_core:Notify(Config.messages['you_leave'] , 'error')
exports.qbx_core:Notify(Lang:t('left_channel'), 'error')
end

local function toggleRadioAnimation(pState)
Expand Down Expand Up @@ -114,25 +114,25 @@ end)
RegisterNUICallback('joinRadio', function(data, cb)
local rchannel = tonumber(data.channel)
if not rchannel then
exports.qbx_core:Notify(Config.messages['invalid_radio'] , 'error')
exports.qbx_core:Notify(Lang:t('invalid_channel'), 'error')
cb("ok")
return
end

if rchannel > Config.MaxFrequency or rchannel == 0 then
exports.qbx_core:Notify(Config.messages['invalid_radio'] , 'error')
exports.qbx_core:Notify(Lang:t('invalid_channel'), 'error')
cb("ok")
return
end

if rchannel == radioChannel then
exports.qbx_core:Notify(Config.messages['you_on_radio'] , 'error')
exports.qbx_core:Notify(Lang:t('on_channel'), 'error')
cb("ok")
return
end

if Config.RestrictedChannels[rchannel] and not Config.RestrictedChannels[rchannel][QBX.PlayerData.job.name] or not QBX.PlayerData.job.onduty then
exports.qbx_core:Notify(Config.messages['restricted_channel_error'], 'error')
exports.qbx_core:Notify(Lang:t('restricted_channel'), 'error')
cb("ok")
return
end
Expand All @@ -142,7 +142,7 @@ end)

RegisterNUICallback('leaveRadio', function(_, cb)
if radioChannel == 0 then
exports.qbx_core:Notify(Config.messages['not_on_radio'], 'error')
exports.qbx_core:Notify(Lang:t('not_on_channel'), 'error')
else
leaveradio()
end
Expand All @@ -152,29 +152,29 @@ end)
RegisterNUICallback("volumeUp", function(_, cb)
if radioVolume <= 95 then
radioVolume = radioVolume + 5
exports.qbx_core:Notify(Config.messages["volume_radio"] .. radioVolume, "success")
exports.qbx_core:Notify(Lang:t('new_volume')..radioVolume, "success")
exports["pma-voice"]:setRadioVolume(radioVolume)
else
exports.qbx_core:Notify(Config.messages["decrease_radio_volume"], "error")
exports.qbx_core:Notify(Lang:t('max_volume'), "error")
end
cb('ok')
end)

RegisterNUICallback("volumeDown", function(_, cb)
if radioVolume >= 10 then
radioVolume = radioVolume - 5
exports.qbx_core:Notify(Config.messages["volume_radio"] .. radioVolume, "success")
exports.qbx_core:Notify(Lang:t('new_volume')..radioVolume, "success")
exports["pma-voice"]:setRadioVolume(radioVolume)
else
exports.qbx_core:Notify(Config.messages["increase_radio_volume"], "error")
exports.qbx_core:Notify(Lang:t('min_volume'), "error")
end
cb('ok')
end)

RegisterNUICallback("increaseradiochannel", function(_, cb)
local newChannel = radioChannel + 1
exports["pma-voice"]:setRadioChannel(newChannel)
exports.qbx_core:Notify(Config.messages["increase_decrease_radio_channel"] .. newChannel, "success")
exports.qbx_core:Notify(Lang:t('new_channel')..newChannel, "success")
cb("ok")
end)

Expand All @@ -183,7 +183,7 @@ RegisterNUICallback("decreaseradiochannel", function(_, cb)
local newChannel = radioChannel - 1
if newChannel >= 1 then
exports["pma-voice"]:setRadioChannel(newChannel)
exports.qbx_core:Notify(Config.messages["increase_decrease_radio_channel"] .. newChannel, "success")
exports.qbx_core:Notify(Lang:t('new_channel')..newChannel, "success")
cb("ok")
end
end)
Expand Down
14 changes: 0 additions & 14 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,3 @@ Config.RestrictedChannels = {
}

Config.MaxFrequency = 500

Config.messages = {
["not_on_radio"] = "You're not connected to a signal",
["on_radio"] = "You're already connected to this signal",
["joined_to_radio"] = "You're connected to: ",
["restricted_channel_error"] = "You can not connect to this signal!",
["invalid_radio"] = "This frequency is not available.",
["you_on_radio"] = "You're already connected to this channel",
["you_leave"] = "You left the channel.",
['volume_radio'] = 'New volume ',
['decrease_radio_volume'] = 'The radio is already set to maximum volume',
['increase_radio_volume'] = 'The radio is already set to the lowest volume',
['increase_decrease_radio_channel'] = 'New channel ',
}
24 changes: 13 additions & 11 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
fx_version 'cerulean'
game 'gta5'

description 'QB-Radio'
description 'QBX-Radio'
repository 'https://github.com/Qbox-project/qbx_radio'
version '1.0.0'

shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/import.lua',
'config.lua'
'@ox_lib/init.lua',
'@qbx_core/import.lua',
'@qbx_core/shared/locale.lua',
'locale/en.lua',
'locale/*.lua',
'config.lua'
}

client_scripts {
'client.lua'
}
client_script 'client.lua'

server_script 'server.lua'

modules {
'qbx_core:playerdata',
'qbx_core:utils',
'qbx_core:playerdata',
'qbx_core:utils',
}

server_script 'server.lua'

ui_page('html/ui.html')

files {'html/ui.html', 'html/js/script.js', 'html/css/style.css', 'html/img/radio.png'}
Expand Down
17 changes: 17 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local Translations = {
not_on_channel = 'You\'re not connected to a channel',
on_channel = 'You\'re already connected to this channel',
joined_radio = 'You\'re connected to: ',
restricted_channel = 'You can not connect to this channel',
invalid_channel = 'This frequency is not available',
left_channel = 'You left the channel',
min_volume = 'The radio is already set to the lowest volume',
max_volume = 'he radio is already set to maximum volume',
new_volume = 'New volume: ',
new_channel = 'New channel: '
}

Lang = Lang or Locale:new({
phrases = Translations,
warnOnMissing = true
})
Loading