refactor(locale): default locale

This commit is contained in:
Linden
2022-05-06 16:00:40 +10:00
parent 5f80c55c31
commit f6b2df0e75
2 changed files with 7 additions and 6 deletions

View File

@@ -1,16 +1,16 @@
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 uiLoaded = false
local userLocale = GetResourceKvpString('locale') local userLocale = GetResourceKvpString('locale') or default[GetCurrentLanguage() + 1]
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)
}) })
SetResourceKvp('locale', locale) SetResourceKvp('locale', locale)
TriggerEvent('ox_lib:setLocale', locale) TriggerEvent('ox_lib:setLocale', locale)
end end
@@ -24,13 +24,14 @@ end)
Citizen.CreateThread(function() Citizen.CreateThread(function()
if not userLocale then userLocale = default[GetCurrentLanguage() + 1] end
while not uiLoaded do Wait(0) end while not uiLoaded do Wait(0) end
loadLocale(userLocale)
SendNUIMessage({ -- Loads the `default` array into select options SendNUIMessage({ -- Loads the `default` array into select options
action = 'loadLocales', action = 'loadLocales',
data = default data = default
}) })
loadLocale(userLocale)
end) end)

View File

@@ -6,5 +6,5 @@ RegisterCommand('serverlocale', function(_, args, _)
end, true) end, true)
function lib.getServerLocale() function lib.getServerLocale()
return GetResourceKvpString('locale') or 'en-US' return GetResourceKvpString('locale') or 'en'
end end