2024-12-30 10:15:34 +00:00
|
|
|
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
|
2024-12-29 20:02:43 +00:00
|
|
|
|
2024-12-30 10:15:34 +00:00
|
|
|
---@param key string
|
|
|
|
function lib.setLocale(key)
|
|
|
|
TriggerEvent('ox_lib:setLocale', key)
|
2024-12-29 20:02:43 +00:00
|
|
|
SendNUIMessage({
|
2024-12-30 10:15:34 +00:00
|
|
|
action = 'setLocale',
|
|
|
|
data = loadLocaleFile(key)
|
2024-12-29 20:02:43 +00:00
|
|
|
})
|
2024-12-30 10:15:34 +00:00
|
|
|
end
|
2024-12-29 20:02:43 +00:00
|
|
|
|
2024-12-30 10:15:34 +00:00
|
|
|
RegisterNUICallback('init', function(_, cb)
|
|
|
|
cb(1)
|
2024-12-29 20:02:43 +00:00
|
|
|
|
|
|
|
SendNUIMessage({
|
|
|
|
action = 'setLocale',
|
2024-12-30 10:15:34 +00:00
|
|
|
data = loadLocaleFile(settings.locale)
|
2024-12-29 20:02:43 +00:00
|
|
|
})
|
|
|
|
end)
|
2024-12-30 10:15:34 +00:00
|
|
|
|
|
|
|
lib.locale(settings.locale)
|