mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
refactor(locale): default locale
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user