mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +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 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 userLocale = GetResourceKvpString('locale')
|
||||||
|
|
||||||
local function loadLocale(locale, cb)
|
local function loadLocale(locale, cb)
|
||||||
if cb then cb(1) end
|
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))
|
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({
|
SendNUIMessage({
|
||||||
action = 'setLocale',
|
action = 'setLocale',
|
||||||
data = json.decode(JSON)
|
data = json.decode(JSON)
|
||||||
@@ -19,10 +22,10 @@ RegisterNUICallback('closeSettings', function(_, cb)
|
|||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not userLocale then userLocale = default[GetCurrentLanguage() + 1] end
|
|
||||||
|
|
||||||
RegisterNUICallback('init', function(_, cb)
|
Citizen.CreateThread(function()
|
||||||
cb(1)
|
if not userLocale then userLocale = default[GetCurrentLanguage() + 1] end
|
||||||
|
while not uiLoaded do Wait(0) end
|
||||||
loadLocale(userLocale)
|
loadLocale(userLocale)
|
||||||
SendNUIMessage({ -- Loads the `default` array into select options
|
SendNUIMessage({ -- Loads the `default` array into select options
|
||||||
action = 'loadLocales',
|
action = 'loadLocales',
|
||||||
@@ -30,6 +33,12 @@ RegisterNUICallback('init', function(_, cb)
|
|||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
RegisterNUICallback('init', function(_, cb)
|
||||||
|
cb(1)
|
||||||
|
uiLoaded = true
|
||||||
|
end)
|
||||||
|
|
||||||
RegisterCommand('ox_lib', function()
|
RegisterCommand('ox_lib', function()
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
action = 'openSettings',
|
action = 'openSettings',
|
||||||
|
|||||||
Reference in New Issue
Block a user