2025-03-18 18:46:09 +11:00
|
|
|
--[[
|
|
|
|
|
https://github.com/overextended/ox_lib
|
|
|
|
|
|
|
|
|
|
This file is licensed under LGPL-3.0 or higher <https://www.gnu.org/licenses/lgpl-3.0.en.html>
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2025 Linden <https://github.com/thelindat/fivem>
|
|
|
|
|
]]
|
|
|
|
|
|
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)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
lib.locale(settings.locale)
|