Skip to content

Commit

Permalink
Check to see if config.lang.lua doesn't load for any reason
Browse files Browse the repository at this point in the history
Moved lang logic to shared.lua
  • Loading branch information
Profex1999 committed Jul 19, 2022
1 parent d866a25 commit f85358f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
23 changes: 0 additions & 23 deletions resource/zth_gcphone/config.lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1041,26 +1041,3 @@ Config.Language = {
},
}
}

if not Config.Language[Config.ChosenLanguage] then
return print("^1[ZTH_Phone] ^0Choosen language does not exists! Please fix the config.lang.lua!")
end

function translate(m, s)
if Config.Language[Config.ChosenLanguage] and Config.Language[Config.ChosenLanguage][m] and Config.Language[Config.ChosenLanguage][m][s] then return Config.Language[Config.ChosenLanguage][m][s] end
for k, _ in pairs(Config.Language[Config.ChosenLanguage]) do if Config.Language[Config.ChosenLanguage][k][m] then return Config.Language[Config.ChosenLanguage][k][m] end end
return ""
end

function getAllScopes(s)
local tb = {}
for k, _ in pairs(Config.Language) do
tb[k] = Config.Language[k][s]
end
return tb
end

function getScope(s)
if Config.Language[Config.ChosenLanguage][s] then return Config.Language[Config.ChosenLanguage][s] end
return {}
end
28 changes: 28 additions & 0 deletions resource/zth_gcphone/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,32 @@ if IsDuplicityVersion() then
gcPhone.debug(translate("NO_XPLAYER_NOTIFICATION"))
end
end
end


if type(Config.Language) ~= "table" then
print("^1[ZTH_Phone] ^0Config.Language is not defined, please check your config.lang.lua file!")
if not Config.Language[Config.ChosenLanguage] then
print("^1[ZTH_Phone] ^0Choosen language does not exists! Please fix the config.lang.lua!")
end
end


function translate(m, s)
if Config.Language[Config.ChosenLanguage] and Config.Language[Config.ChosenLanguage][m] and Config.Language[Config.ChosenLanguage][m][s] then return Config.Language[Config.ChosenLanguage][m][s] end
for k, _ in pairs(Config.Language[Config.ChosenLanguage]) do if Config.Language[Config.ChosenLanguage][k][m] then return Config.Language[Config.ChosenLanguage][k][m] end end
return ""
end

function getAllScopes(s)
local tb = {}
for k, _ in pairs(Config.Language) do
tb[k] = Config.Language[k][s]
end
return tb
end

function getScope(s)
if Config.Language[Config.ChosenLanguage][s] then return Config.Language[Config.ChosenLanguage][s] end
return {}
end

0 comments on commit f85358f

Please sign in to comment.