-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.lua
71 lines (68 loc) · 2.07 KB
/
server.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
translations = {}
local files = {}
local language = "en"
local packages = nil
local function readFile(name)
local fh = io.open(name, "r")
if fh == nil then
return nil
end
fh:close()
local content = ""
for line in io.lines(name) do
content = content..line
end
return content
end
local function loadConfig()
local fileContent = readFile("server_config.json")
if fileContent ~= nil then
local serverConfig = json_decode(fileContent)
packages = serverConfig.packages
else
print("[i18n] server_config.json not found, falling back on i18n.json")
end
fileContent = readFile("i18n.json")
if fileContent == nil then
if packages == nil then
print("[i18n] server_config.json and i18n.json not found, no translations are loaded")
end
return
end
local config = json_decode(fileContent)
if config.language ~= nil then
language = config.language
if packages == nil then
packages = config.packages
end
end
if packages == nil then
print("[i18n] server_config.json not found and i18n.json has no packages property, no translations are loaded")
packages = {}
end
end
loadConfig()
for i=1,#packages do
local fileContent = readFile("packages/"..packages[i].."/i18n/"..language..".json")
if fileContent == nil then
if language ~= "en" then
fileContent = readFile("packages/"..packages[i].."/i18n/en.json")
end
end
if fileContent ~= nil then
files[packages[i]] = fileContent
translations[packages[i]] = json_decode(fileContent)
end
end
AddEvent("OnPlayerJoin", function(player)
for k,v in pairs(files) do
CallRemoteEvent(player, "i18n_start_file", k, v:len())
local offset = 1
while offset < v:len() do
CallRemoteEvent(player, "i18n_send_file_data", k, v:sub(offset, offset + 999))
offset = offset + 1000
end
end
CallRemoteEvent(player, "i18n_ready")
CallEvent("OnTranslationReady", player)
end)