mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
fix(client): Move loadLocale function out of init
Setting a locale causes the whole application to be rerendered, meaning that the fetch for init would also run every time when locale is set
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
local default = { 'en', 'fr', 'de', 'it', 'es', 'pt-BR', 'pl', 'ru', 'ko', 'zh-TW', 'ja', 'es-MX', 'zh-CN' }
|
||||
local uiLoaded = false
|
||||
local userLocale = GetResourceKvpString('locale')
|
||||
|
||||
local function loadLocale(locale, cb)
|
||||
if cb then cb(1) end
|
||||
if not locale then locale = userLocale 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)
|
||||
@@ -19,10 +22,10 @@ RegisterNUICallback('closeSettings', function(_, cb)
|
||||
SetNuiFocus(false, false)
|
||||
end)
|
||||
|
||||
if not userLocale then userLocale = default[GetCurrentLanguage() + 1] end
|
||||
|
||||
RegisterNUICallback('init', function(_, cb)
|
||||
cb(1)
|
||||
Citizen.CreateThread(function()
|
||||
if not userLocale then userLocale = default[GetCurrentLanguage() + 1] end
|
||||
while not uiLoaded do Wait(0) end
|
||||
loadLocale(userLocale)
|
||||
SendNUIMessage({ -- Loads the `default` array into select options
|
||||
action = 'loadLocales',
|
||||
@@ -30,6 +33,12 @@ RegisterNUICallback('init', function(_, cb)
|
||||
})
|
||||
end)
|
||||
|
||||
|
||||
RegisterNUICallback('init', function(_, cb)
|
||||
cb(1)
|
||||
uiLoaded = true
|
||||
end)
|
||||
|
||||
RegisterCommand('ox_lib', function()
|
||||
SendNUIMessage({
|
||||
action = 'openSettings',
|
||||
|
||||
Reference in New Issue
Block a user