mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(locale): locale hotloading
This commit is contained in:
@@ -1,15 +1,33 @@
|
||||
local settings = require 'resource.settings'
|
||||
|
||||
local function loadLocaleFile(key)
|
||||
local file = LoadResourceFile(cache.resource, ('locales/%s.json'):format(key))
|
||||
or LoadResourceFile(cache.resource, 'locales/en.json')
|
||||
|
||||
return file and json.decode(file) or {}
|
||||
end
|
||||
|
||||
function lib.getLocaleKey() return settings.locale end
|
||||
|
||||
---@param key string
|
||||
function lib.setLocale(key)
|
||||
settings.locale = key
|
||||
|
||||
SetResourceKvp('locale', key)
|
||||
TriggerEvent('ox_lib:setLocale', key)
|
||||
SendNUIMessage({
|
||||
action = 'setLocale',
|
||||
data = loadLocaleFile(key)
|
||||
})
|
||||
end
|
||||
|
||||
RegisterNUICallback('init', function(_, cb)
|
||||
cb(1)
|
||||
|
||||
SendNUIMessage({
|
||||
action = 'loadLocales',
|
||||
data = {}
|
||||
})
|
||||
|
||||
local JSON = LoadResourceFile(cache.resource, ('locales/%s.json'):format(GetConvar('ox:locale', 'en'))) or LoadResourceFile(cache.resource, 'locales/en.json')
|
||||
|
||||
SendNUIMessage({
|
||||
action = 'setLocale',
|
||||
data = JSON and json.decode(JSON) or {}
|
||||
data = loadLocaleFile(settings.locale)
|
||||
})
|
||||
end)
|
||||
|
||||
lib.locale(settings.locale)
|
||||
|
||||
Reference in New Issue
Block a user