Skip to content

Commit

Permalink
feat(settings): ox:userLocales convar
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Apr 19, 2024
1 parent 3959f76 commit 3df1836
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"language": "English",
"settings": "Settings",
"ui": {
"cancel": "Cancel",
"close": "Close",
Expand Down
40 changes: 24 additions & 16 deletions resource/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ local settings = {
notification_audio = GetResourceKvpInt('notification_audio') == 1
}

settings.locale = GetResourceKvpString('locale') or settings.default_locale
local userLocales = GetConvarInt('ox:userLocales', 1) == 1

settings.locale = userLocales and GetResourceKvpString('locale') or settings.default_locale

local function set(key, value)
if settings[key] == value then return false end
Expand All @@ -36,16 +38,11 @@ local function set(key, value)
end

RegisterCommand('ox_lib', function()
local input = lib.inputDialog('Settings', {
local inputSettings = {
{
type = 'select',
label = locale('ui.settings.locale'),
searchable = true,
description = locale('ui.settings.locale_description', settings.locale),
options = GlobalState['ox_lib:locales'],
default = settings.locale,
required = true,
icon = 'book',
type = 'checkbox',
label = locale('ui.settings.notification_audio'),
checked = settings.notification_audio,
},
{
type = 'select',
Expand All @@ -64,12 +61,23 @@ RegisterCommand('ox_lib', function()
required = true,
icon = 'message',
},
{
type = 'checkbox',
label = locale('ui.settings.notification_audio'),
checked = settings.notification_audio,
}
}) --[[@as table?]]
}

if userLocales then
table.insert(inputSettings,
{
type = 'select',
label = locale('ui.settings.locale'),
searchable = true,
description = locale('ui.settings.locale_description', settings.locale),
options = GlobalState['ox_lib:locales'],
default = settings.locale,
required = true,
icon = 'book',
})
end

local input = lib.inputDialog(locale('settings'), inputSettings) --[[@as table?]]

if not input then return end

Expand Down

0 comments on commit 3df1836

Please sign in to comment.