refactor(server/locale): get array of valid locales

This commit is contained in:
Linden
2022-05-06 16:37:36 +10:00
parent f6b2df0e75
commit d4b5e0402c
3 changed files with 28 additions and 3 deletions

View File

@@ -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, _)
if args?[1] then
SetResourceKvp('locale', args[1])