Files
ox_lib/resource/locale/client.lua

39 lines
929 B
Lua
Raw Normal View History

--[[
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>
2025-03-29 21:44:03 +11:00
Copyright © 2025 Linden <https://github.com/thelindat>
]]
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)
SendNUIMessage({
2024-04-01 19:16:53 +11:00
action = 'setLocale',
data = loadLocaleFile(key)
})
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
})
end)
2024-04-01 19:16:53 +11:00
lib.locale(settings.locale)