feat(web): Settings modal, locale state provider

This commit is contained in:
Luke
2022-04-30 14:49:49 +02:00
parent 48728f0241
commit 4db4c79d8a
8 changed files with 256 additions and 16 deletions

View File

@@ -1,21 +1,42 @@
local default = { 'en', 'fr', 'de', 'it', 'es', 'pt-BR', 'pl', 'ru', 'ko', 'zh-TW', 'ja', 'es-MX', 'zh-CN' }
local userLocale = GetResourceKvpString('locale')
local function loadLocale(locale, cb)
if cb then cb(1) end
local JSON = LoadResourceFile('ox_lib', ('locales/%s.json'):format(locale)) or LoadResourceFile('ox_lib', ('locales/en.json'):format(locale))
if cb then cb(JSON) end
SendNUIMessage({
action = 'setLocale',
data = json.decode(JSON)
})
SetResourceKvp('locale', locale)
TriggerEvent('ox_lib:setLocale', locale)
end
RegisterNUICallback('getLocale', loadLocale)
if not userLocale then
local default = { 'en', 'fr', 'de', 'it', 'es', 'pt-BR', 'pl', 'ru', 'ko', 'zh-TW', 'ja', 'es-MX', 'zh-CN' }
userLocale = default[GetCurrentLanguage() + 1]
end
RegisterNUICallback('closeSettings', function(_, cb)
cb(1)
SetNuiFocus(false, false)
end)
loadLocale(userLocale)
if not userLocale then userLocale = default[GetCurrentLanguage() + 1] end
RegisterNUICallback('init', function(_, cb)
cb(1)
loadLocale(userLocale)
SendNUIMessage({ -- Loads the `default` array into select options
action = 'loadLocales',
data = default
})
end)
RegisterCommand('ox_lib', function()
SendNUIMessage({
action = 'openSettings',
data = GetResourceKvpString('locale') -- Sets the value for language select
})
SetNuiFocus(true, true)
end)
RegisterCommand('setlocale', function(_, args, _)
if args?[1] then