mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(server/locale): get array of valid locales
This commit is contained in:
@@ -26,6 +26,6 @@ end
|
|||||||
AddEventHandler('ox_lib:setLocale', loadLocale)
|
AddEventHandler('ox_lib:setLocale', loadLocale)
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
local lang = IsDuplicityVersion() and lib.getServerLocale() or GetExternalKvpString('ox_lib', 'locale') or 'en'
|
local lang = lib.service == 'server' and lib.getServerLocale() or GetExternalKvpString('ox_lib', 'locale') or 'en'
|
||||||
loadLocale(lang)
|
loadLocale(lang)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,26 @@
|
|||||||
|
do
|
||||||
|
local locales = {}
|
||||||
|
local system = os.getenv('OS')
|
||||||
|
local command = system and system:match('Windows') and 'dir "' or 'ls "'
|
||||||
|
local path = GetResourcePath(lib.name)
|
||||||
|
local types = path:gsub('//', '/') .. '/locales'
|
||||||
|
local suffix = command == 'dir "' and '/" /b' or '/"'
|
||||||
|
local dir = io.popen(command .. types .. suffix)
|
||||||
|
|
||||||
|
if dir then
|
||||||
|
for line in dir:lines() do
|
||||||
|
local file = line:gsub('([%a%-]+).json', '%1')
|
||||||
|
|
||||||
|
if file then
|
||||||
|
locales[#locales+1] = file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
dir:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
GlobalState.locales = locales
|
||||||
|
end
|
||||||
|
|
||||||
RegisterCommand('serverlocale', function(_, args, _)
|
RegisterCommand('serverlocale', function(_, args, _)
|
||||||
if args?[1] then
|
if args?[1] then
|
||||||
SetResourceKvp('locale', args[1])
|
SetResourceKvp('locale', args[1])
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
lib = setmetatable({}, {
|
lib = setmetatable({
|
||||||
|
name = 'ox_lib'
|
||||||
|
}, {
|
||||||
__newindex = function(self, name, fn)
|
__newindex = function(self, name, fn)
|
||||||
exports(name, fn)
|
exports(name, fn)
|
||||||
rawset(self, name, fn)
|
rawset(self, name, fn)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
if not LoadResourceFile('ox_lib', 'web/build/index.html') then
|
if not LoadResourceFile(lib.name, 'web/build/index.html') then
|
||||||
error('Unable to load UI. Build ox_lib or download the latest release.\n ^3https://github.com/overextended/ox_lib/releases/latest/download/ox_lib.zip^0')
|
error('Unable to load UI. Build ox_lib or download the latest release.\n ^3https://github.com/overextended/ox_lib/releases/latest/download/ox_lib.zip^0')
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user