refactor(locale): simplify

BREAKING CHANGE (kind of)
Remove user-selection for locales. Adds mostly unnecessary complexity,
and most people don't want to bother with it anyway.

Locale is always based on the convar "ox:locale" instead.
This commit is contained in:
Linden
2022-10-18 21:17:26 +11:00
parent 5b2c74afa0
commit 671be5e7a2
3 changed files with 17 additions and 86 deletions

View File

@@ -1,47 +1,9 @@
local default = { 'en', 'fr', 'de', 'it', 'es', 'pt-BR', 'pl', 'ru', 'ko', 'zh-TW', 'ja', 'es-MX', 'zh-CN' }
local userLocale = GetResourceKvpString('locale') or default[GetCurrentLanguage() + 1]
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))
SendNUIMessage({
action = 'setLocale',
data = json.decode(JSON)
})
SetResourceKvp('locale', locale)
TriggerEvent('ox_lib:setLocale', locale)
end
RegisterNUICallback('getLocale', loadLocale)
RegisterNUICallback('closeSettings', function(_, cb)
cb(1)
SetNuiFocus(false, false)
end)
---@todo remove module and nui event
RegisterNUICallback('init', function(_, cb)
cb(1)
cb(1)
SendNUIMessage({
action = 'loadLocales',
data = GlobalState.locales
})
loadLocale(userLocale)
SendNUIMessage({
action = 'loadLocales',
data = {}
})
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
loadLocale(args[1])
end
end, false)