2024-04-01 19:16:53 +11: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
|
2022-05-06 16:00:40 +10:00
|
|
|
|
2024-04-01 19:16:53 +11:00
|
|
|
---@param key string
|
|
|
|
|
function lib.setLocale(key)
|
|
|
|
|
settings.locale = key
|
|
|
|
|
|
|
|
|
|
SetResourceKvp('locale', key)
|
|
|
|
|
TriggerEvent('ox_lib:setLocale', key)
|
2022-10-18 21:17:26 +11:00
|
|
|
SendNUIMessage({
|
2024-04-01 19:16:53 +11:00
|
|
|
action = 'setLocale',
|
|
|
|
|
data = loadLocaleFile(key)
|
2022-10-18 21:17:26 +11:00
|
|
|
})
|
2024-04-01 19:16:53 +11:00
|
|
|
end
|
2022-10-19 04:14:36 +11:00
|
|
|
|
2024-04-01 19:16:53 +11:00
|
|
|
RegisterNUICallback('init', function(_, cb)
|
|
|
|
|
cb(1)
|
2022-10-19 04:14:36 +11:00
|
|
|
|
|
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'setLocale',
|
2024-04-01 19:16:53 +11:00
|
|
|
data = loadLocaleFile(settings.locale)
|
2022-10-19 04:14:36 +11:00
|
|
|
})
|
2022-04-30 14:49:49 +02:00
|
|
|
end)
|
2024-04-01 19:16:53 +11:00
|
|
|
|
2024-04-02 17:00:59 +11:00
|
|
|
if not settings.locale then lib.setLocale(GetConvar('ox:locale', 'en')) end
|
|
|
|
|
|
2024-04-01 19:16:53 +11:00
|
|
|
lib.locale(settings.locale)
|