feat(locale): locale hotloading

This commit is contained in:
Linden
2024-04-01 19:16:53 +11:00
parent 09ca963f26
commit 1e3b2cb567
4 changed files with 49 additions and 10 deletions

View File

@@ -38,10 +38,12 @@ function lib.getLocales()
end
---Loads the ox_lib locale module. Prefer using fxmanifest instead (see [docs](https://overextended.dev/ox_lib#usage)).
function lib.locale()
local lang = GetConvar('ox:locale', 'en')
function lib.locale(key)
local lang = key or lib.getLocaleKey()
local locales = json.decode(LoadResourceFile(cache.resource, ('locales/%s.json'):format(lang)))
table.wipe(dict)
if not locales then
local warning = "could not load 'locales/%s.json'"
warn(warning:format(lang))
@@ -104,4 +106,8 @@ exports('getLocale', function(key)
return dict[key]
end)
AddEventHandler('ox_lib:setLocale', function(key)
lib.locale(key)
end)
return lib.locale