Feat: extend the translation system

This commit is contained in:
Linventif 2024-08-16 15:01:55 +00:00
parent 2e0e52eb37
commit c97f817a51
10 changed files with 109 additions and 35 deletions

View File

@ -12,7 +12,7 @@ list.Set("DesktopWindows", "GmodIntegration:DesktopWindows", {
list.Set("DesktopWindows", "GmodIntegration:DesktopWindows:ReportBug", { list.Set("DesktopWindows", "GmodIntegration:DesktopWindows:ReportBug", {
icon = "gmod_integration/logo_context_report.png", icon = "gmod_integration/logo_context_report.png",
title = language.GetPhrase("gmod_integration.report_bug.title", "Report Bug"), title = gmInte.getTranslation("report_bug.title", "Report Bug"),
width = 960, width = 960,
height = 700, height = 700,
onewindow = true, onewindow = true,

View File

@ -1,24 +1,43 @@
function gmInte.chatAddText(data) function gmInte.getTranslation(key, default, ...)
key = "gmod_integration." .. key
local translation = language.GetPhrase(key)
if translation == key then translation = default end
if ... then
for i = 1, select("#", ...) do
translation = string.Replace(translation, "{" .. i .. "}", select(i, ...))
end
end
return translation
end
function gmInte.chatAddText(...)
local args = {...}
table.insert(args, 1, Color(255, 130, 92))
table.insert(args, 2, "[Gmod Integration] ")
chat.AddText(unpack(args))
end
function gmInte.chatAddTextFromTable(data)
local args = {} local args = {}
for _, v in ipairs(data) do for _, v in ipairs(data) do
table.insert(args, v.color) table.insert(args, v.color || Color(255, 255, 255))
table.insert(args, v.text) table.insert(args, v.text)
end end
chat.AddText(unpack(args)) gmInte.chatAddText(unpack(args))
end end
function gmInte.showTestConnection(data) function gmInte.showTestConnection(data)
if data && data.id then if data && data.id then
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(63, 102, 63), "Connection Successfull", Color(255, 255, 255), ", server logged as '" .. data.name .. "'") gmInte.chatAddText(Color(89, 194, 89), gmInte.getTranslation("gmod_integration.chat.authentication_success", "Successfully Authenticated"), Color(255, 255, 255), gmInte.getTranslation("gmod_integration.chat.server_link", ", server linked as {1}.", data.name))
else else
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "Connection Failed", Color(255, 255, 255), ", please check your ID and Token") gmInte.chatAddText(Color(228, 81, 81), gmInte.getTranslation("gmod_integration.chat.authentication_failed", "Failed to Authenticate"), Color(255, 255, 255), gmInte.getTranslation("gmod_integration.chat.server_fail", ", check your ID and Token."))
end end
end end
function gmInte.openAdminConfig() function gmInte.openAdminConfig()
if !LocalPlayer():gmIntIsAdmin() then if !LocalPlayer():gmIntIsAdmin() then
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "You are not superadmin") gmInte.chatAddText(Color(228, 81, 81), gmInte.getTranslation("chat.missing_permissions", "You do not have permission to do this action."))
return return
end end

View File

@ -25,7 +25,7 @@ local netReceive = {
gmInte.version = data.other.version gmInte.version = data.other.version
if !data.other.aprovedCredentials then RunConsoleCommand("gmod_integration_admin") end if !data.other.aprovedCredentials then RunConsoleCommand("gmod_integration_admin") end
end, end,
[6] = function(data) gmInte.chatAddText(data) end, [6] = function(data) gmInte.chatAddTextFromTable(data) end,
[7] = function() gmInte.openVerifPopup() end, [7] = function() gmInte.openVerifPopup() end,
[8] = function(data) gmInte.config.token = data.token end [8] = function(data) gmInte.config.token = data.token end
} }

View File

@ -1,46 +1,49 @@
local Fields = { local Fields = {
{ {
["title"] = language.GetPhrase("gmod_integration.report_bug.title", "Report a bug"), ["title"] = gmInte.getTranslation("report_bug.title", "Report a bug"),
["type"] = "image", ["type"] = "image",
}, },
{ {
["title"] = language.GetPhrase("gmod_integration.report_bug.description", "Report a bug to the developers of this game."), ["title"] = gmInte.getTranslation("report_bug.description", "Report a bug to the developers of this game."),
["type"] = "text", ["type"] = "text",
["dsc"] = language.GetPhrase("gmod_integration.report_bug.description.dsc", "Please provide as much information as possible to help us fix the issue."), ["dsc"] = gmInte.getTranslation("report_bug.description.dsc", "Please provide as much information as possible to help us fix the issue."),
["tall"] = 80, ["tall"] = 80,
}, },
{ {
["title"] = language.GetPhrase("gmod_integration.report_bug.importance_level", "Importance Level"), ["title"] = gmInte.getTranslation("report_bug.importance_level", "Importance Level"),
["type"] = "dropdown", ["type"] = "dropdown",
["options"] = { ["options"] = {
["critical"] = language.GetPhrase("gmod_integration.report_bug.importance_level.critical", "Critical - Crash or made the game unplayable."), ["critical"] = gmInte.getTranslation("report_bug.importance_level.critical", "Critical - Crash or made the game unplayable."),
["high"] = language.GetPhrase("gmod_integration.report_bug.importance_level.high", "High - Critical functionality is unusable."), ["high"] = gmInte.getTranslation("report_bug.importance_level.high", "High - Critical functionality is unusable."),
["medium"] = language.GetPhrase("gmod_integration.report_bug.importance_level.medium", "Medium - Important functionality is unusable."), ["medium"] = gmInte.getTranslation("report_bug.importance_level.medium", "Medium - Important functionality is unusable."),
["low"] = language.GetPhrase("gmod_integration.report_bug.importance_level.low", "Low - Cosmetic issue."), ["low"] = gmInte.getTranslation("report_bug.importance_level.low", "Low - Cosmetic issue."),
["trivial"] = language.GetPhrase("gmod_integration.report_bug.importance_level.trivial", "Trivial - Very minor issue."), ["trivial"] = gmInte.getTranslation("report_bug.importance_level.trivial", "Trivial - Very minor issue."),
}, },
}, },
{ {
["title"] = language.GetPhrase("gmod_integration.report_bug.steps_to_reproduce", "Steps to Reproduce"), ["title"] = gmInte.getTranslation("report_bug.steps_to_reproduce", "Steps to Reproduce"),
["type"] = "text", ["type"] = "text",
["dsc"] = language.GetPhrase("gmod_integration.report_bug.steps_to_reproduce.dsc", "Please provide a step-by-step guide on how to reproduce the bug."), ["dsc"] = gmInte.getTranslation("report_bug.steps_to_reproduce.dsc", "Please provide a step-by-step guide on how to reproduce the bug."),
["tall"] = 80, ["tall"] = 80,
}, },
{ {
["title"] = language.GetPhrase("gmod_integration.report_bug.expected_result", "Expected result"), ["title"] = gmInte.getTranslation("report_bug.expected_result", "Expected result"),
["type"] = "text", ["type"] = "text",
["dsc"] = language.GetPhrase("gmod_integration.report_bug.expected_result.dsc", "What did you expect to happen?"), ["dsc"] = gmInte.getTranslation("report_bug.expected_result.dsc", "What did you expect to happen?"),
["tall"] = 50, ["tall"] = 50,
}, },
{ {
["title"] = language.GetPhrase("gmod_integration.report_bug.actual_result", "Actual result"), ["title"] = gmInte.getTranslation("report_bug.actual_result", "Actual result"),
["type"] = "text", ["type"] = "text",
["dsc"] = language.GetPhrase("gmod_integration.report_bug.actual_result.dsc", "What actually happened?"), ["dsc"] = gmInte.getTranslation("report_bug.actual_result.dsc", "What actually happened?"),
["tall"] = 50, ["tall"] = 50,
}, },
} }
function gmInte.openReportBug() local ScreenshotRequested = false
hook.Add("PostRender", "gmInte:BugReport:Screenshot", function()
if !ScreenshotRequested then return end
ScreenshotRequested = false
local captureData = { local captureData = {
format = "jpeg", format = "jpeg",
x = 0, x = 0,
@ -52,10 +55,31 @@ function gmInte.openReportBug()
local screenCapture = render.Capture(captureData) local screenCapture = render.Capture(captureData)
if screenCapture then file.Write("gmod_integration/report_bug_screenshot.jpeg", screenCapture) end if screenCapture then file.Write("gmod_integration/report_bug_screenshot.jpeg", screenCapture) end
end)
function gmInte.openReportBug()
// notification.AddLegacy(gmInte.getTranslation("report_bug.info", "Please wait few seconds to take a screenshot"), NOTIFY_GENERIC, 5)
// ScreenshotRequested = true
// // wait the screenshot to be taken
// local try = 0
// local screenFailed = false
// timer.Create("gmInte:BugReport:Screenshot", 0.5, 0, function()
// if !file.Exists("gmod_integration/report_bug_screenshot.jpeg", "DATA") then
// try = try + 1
// if try >= 3 then
// notification.AddLegacy(gmInte.getTranslation("report_bug.error.failed_screenshot", "Failed to take screenshot, retry later"), NOTIFY_ERROR, 5)
// timer.Remove("gmInte:BugReport:Screenshot")
// screenFailed = true
// end
// return
// end
// timer.Remove("gmInte:BugReport:Screenshot")
// gmInte.openReportBugFrame()
// end)
local frame = vgui.Create("DFrame") local frame = vgui.Create("DFrame")
frame:SetSize(500, (700 / 1080) * ScrH()) frame:SetSize(500, (700 / 1080) * ScrH())
frame:Center() frame:Center()
frame:SetTitle(gmInte.getFrameName(language.GetPhrase("gmod_integration.report_bug.title", "Report Bug"))) frame:SetTitle(gmInte.getFrameName(gmInte.getTranslation("report_bug.title", "Report Bug")))
frame:MakePopup() frame:MakePopup()
gmInte.applyPaint(frame) gmInte.applyPaint(frame)
// bug report = screenshot, description, steps to reproduce, expected result, actual result // bug report = screenshot, description, steps to reproduce, expected result, actual result
@ -65,7 +89,6 @@ function gmInte.openReportBug()
local elements = {} local elements = {}
for _ = 1, #Fields do for _ = 1, #Fields do
local field = Fields[_] local field = Fields[_]
if field.type == "image" && !screenCapture then continue end
local label = vgui.Create("DLabel", dPanel) local label = vgui.Create("DLabel", dPanel)
label:Dock(TOP) label:Dock(TOP)
label:DockMargin(5, 5, 5, 5) label:DockMargin(5, 5, 5, 5)
@ -89,7 +112,7 @@ function gmInte.openReportBug()
local dropdown = vgui.Create("DComboBox", dPanel) local dropdown = vgui.Create("DComboBox", dPanel)
dropdown:Dock(TOP) dropdown:Dock(TOP)
dropdown:DockMargin(5, 5, 5, 5) dropdown:DockMargin(5, 5, 5, 5)
dropdown:SetValue(language.GetPhrase("gmod_integration.report_bug.importance_level.dsc", "How important is this bug?")) dropdown:SetValue(gmInte.getTranslation("report_bug.importance_level.dsc", "How important is this bug?"))
for key, value in pairs(field.options) do for key, value in pairs(field.options) do
dropdown:AddChoice(value, key) dropdown:AddChoice(value, key)
end end
@ -119,7 +142,7 @@ function gmInte.openReportBug()
if !elements[4]:GetText() || elements[4]:GetText() == "" then readyForSend = false end if !elements[4]:GetText() || elements[4]:GetText() == "" then readyForSend = false end
if !elements[5]:GetText() || elements[5]:GetText() == "" then readyForSend = false end if !elements[5]:GetText() || elements[5]:GetText() == "" then readyForSend = false end
if !readyForSend then if !readyForSend then
notification.AddLegacy(language.GetPhrase("gmod_integration.report_bug.error.missing_fields", "All fields are required"), NOTIFY_ERROR, 5) notification.AddLegacy(gmInte.getTranslation("report_bug.error.missing_fields", "All fields are required"), NOTIFY_ERROR, 5)
return return
end end
@ -144,9 +167,9 @@ function gmInte.openReportBug()
["expected"] = elements[4]:GetText(), ["expected"] = elements[4]:GetText(),
["actual"] = elements[5]:GetText(), ["actual"] = elements[5]:GetText(),
}, function() }, function()
notification.AddLegacy(language.GetPhrase("gmod_integration.report_bug.success", "Bug report sent successfully"), NOTIFY_GENERIC, 5) notification.AddLegacy(gmInte.getTranslation("report_bug.success", "Bug report sent successfully"), NOTIFY_GENERIC, 5)
frame:Close() frame:Close()
end, function() notification.AddLegacy(language.GetPhrase("gmod_integration.report_bug.error.failed", "Failed to send bug report retry later"), NOTIFY_ERROR, 5) end) end, function() notification.AddLegacy(gmInte.getTranslation("report_bug.error.failed", "Failed to send bug report retry later"), NOTIFY_ERROR, 5) end)
end end
end end

View File

@ -23,7 +23,7 @@ hook.Add("PostRender", "gmInteScreenshot", function()
return return
else else
FailAttempts = 0 FailAttempts = 0
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "Failed to take screenshot, your system may not support this feature.") gmInte.chatAddText(Color(255, 255, 255), gmInte.getTranslation("chat.error.screenshot_failed", "Failed to take screenshot, your system may not support this feature."))
return return
end end
end end
@ -36,10 +36,7 @@ hook.Add("PostRender", "gmInteScreenshot", function()
["screenshot"] = base64Capture, ["screenshot"] = base64Capture,
["captureData"] = captureData, ["captureData"] = captureData,
["size"] = size .. "KB" ["size"] = size .. "KB"
}, function(code, body) }, function(code, body) gmInte.chatAddText(Color(255, 130, 92), gmInte.getTranslation("chat.screenshot.sent", "Screenshot sent to Discord.")) end, function(code, body) gmInte.log("Screenshot failed to send to Discord, error code: " .. code, true) end)
gmInte.log("Screenshot sent to Discord", true)
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(255, 255, 255), "Screenshot sent to Discord.")
end, function(code, body) gmInte.log("Screenshot failed to send to Discord, error code: " .. code, true) end)
end) end)
function gmInte.takeScreenShot() function gmInte.takeScreenShot()

View File

@ -22,3 +22,10 @@ gmod_integration.report_bug.description.dsc=Bitte geben Sie so viele Information
gmod_integration.report_bug.error.missing_fields=Bitte füllen Sie vor dem Absenden des Fehlerberichts alle erforderlichen Felder aus. gmod_integration.report_bug.error.missing_fields=Bitte füllen Sie vor dem Absenden des Fehlerberichts alle erforderlichen Felder aus.
gmod_integration.report_bug.success=Fehlerbericht erfolgreich gesendet gmod_integration.report_bug.success=Fehlerbericht erfolgreich gesendet
gmod_integration.report_bug.error.failed=Senden des Fehlerberichts fehlgeschlagen. Bitte versuchen Sie es später erneut. gmod_integration.report_bug.error.failed=Senden des Fehlerberichts fehlgeschlagen. Bitte versuchen Sie es später erneut.
gmod_integration.chat.missing_permissions=Sie haben keine Berechtigung, diese Aktion auszuführen.
gmod_integration.chat.authentication_success=Erfolgreich authentifiziert
gmod_integration.chat.authentication_failed=Authentifizierung fehlgeschlagen
gmod_integration.chat.server_link=, Server verknüpft als {1}.
gmod_integration.chat.server_fail=, überprüfen Sie Ihre ID und Ihr Token.
gmod_integration.chat.error.screenshot_failed=Fehler beim Erstellen des Screenshots. Ihr System unterstützt diese Funktion möglicherweise nicht.
gmod_integration.chat.screenshot.sent=Screenshot an Discord gesendet.

View File

@ -22,3 +22,10 @@ gmod_integration.report_bug.description.dsc=Please provide as much information a
gmod_integration.report_bug.error.missing_fields=Before submitting the bug report, please fill in all the required fields. gmod_integration.report_bug.error.missing_fields=Before submitting the bug report, please fill in all the required fields.
gmod_integration.report_bug.success=Bug report sent successfully gmod_integration.report_bug.success=Bug report sent successfully
gmod_integration.report_bug.error.failed=Failed to send bug report, please try again later. gmod_integration.report_bug.error.failed=Failed to send bug report, please try again later.
gmod_integration.chat.missing_permissions=You do not have permission to do this action.
gmod_integration.chat.authentication_success=Successfully Authenticated
gmod_integration.chat.authentication_failed=Failed to Authenticate
gmod_integration.chat.server_link=, server linked as {1}.
gmod_integration.chat.server_fail=, check your ID and Token.
gmod_integration.chat.error.screenshot_failed=Failed to take screenshot, your system may not support this feature.
gmod_integration.chat.screenshot.sent=Screenshot sent to Discord.

View File

@ -22,3 +22,10 @@ gmod_integration.report_bug.description.dsc=Proporciona la mayor cantidad de inf
gmod_integration.report_bug.error.missing_fields=Antes de enviar el informe de error, completa todos los campos requeridos. gmod_integration.report_bug.error.missing_fields=Antes de enviar el informe de error, completa todos los campos requeridos.
gmod_integration.report_bug.success=Informe de error enviado correctamente gmod_integration.report_bug.success=Informe de error enviado correctamente
gmod_integration.report_bug.error.failed=Error al enviar el informe de error, inténtalo de nuevo más tarde. gmod_integration.report_bug.error.failed=Error al enviar el informe de error, inténtalo de nuevo más tarde.
gmod_integration.chat.missing_permissions=No tienes permiso para realizar esta acción.
gmod_integration.chat.authentication_success=Autenticación exitosa
gmod_integration.chat.authentication_failed=Error de autenticación
gmod_integration.chat.server_link=, servidor vinculado como {1}.
gmod_integration.chat.server_fail=, verifica tu ID y Token.
gmod_integration.chat.error.screenshot_failed=Error al tomar la captura de pantalla, es posible que tu sistema no admita esta función.
gmod_integration.chat.screenshot.sent=Captura de pantalla enviada a Discord.

View File

@ -22,3 +22,10 @@ gmod_integration.report_bug.description.dsc=Veuillez fournir autant d'informatio
gmod_integration.report_bug.error.missing_fields=Avant d'envoyer le rapport de bug, veuillez remplir tous les champs obligatoires. gmod_integration.report_bug.error.missing_fields=Avant d'envoyer le rapport de bug, veuillez remplir tous les champs obligatoires.
gmod_integration.report_bug.success=Rapport de bug envoyé avec succès gmod_integration.report_bug.success=Rapport de bug envoyé avec succès
gmod_integration.report_bug.error.failed=Échec de l'envoi du rapport de bug, veuillez réessayer ultérieurement. gmod_integration.report_bug.error.failed=Échec de l'envoi du rapport de bug, veuillez réessayer ultérieurement.
gmod_integration.chat.missing_permissions=Vous n'avez pas la permission de faire cette action.
gmod_integration.chat.authentication_success=Authentification réussie
gmod_integration.chat.authentication_failed=Échec de l'authentification
gmod_integration.chat.server_link=, serveur lié en tant que {1}.
gmod_integration.chat.server_fail=, vérifiez votre ID et votre jeton.
gmod_integration.chat.error.screenshot_failed=Échec de la capture d'écran, votre système peut ne pas prendre en charge cette fonctionnalité.
gmod_integration.chat.screenshot.sent=Capture d'écran envoyée sur Discord.

View File

@ -22,3 +22,10 @@ gmod_integration.report_bug.description.dsc=Пожалуйста, предост
gmod_integration.report_bug.error.missing_fields=Перед отправкой отчета об ошибке, заполните все обязательные поля. gmod_integration.report_bug.error.missing_fields=Перед отправкой отчета об ошибке, заполните все обязательные поля.
gmod_integration.report_bug.success=Отчет об ошибке успешно отправлен gmod_integration.report_bug.success=Отчет об ошибке успешно отправлен
gmod_integration.report_bug.error.failed=Не удалось отправить отчет об ошибке, пожалуйста, попробуйте еще раз позже. gmod_integration.report_bug.error.failed=Не удалось отправить отчет об ошибке, пожалуйста, попробуйте еще раз позже.
gmod_integration.chat.missing_permissions=У вас нет разрешения на выполнение этого действия.
gmod_integration.chat.authentication_success=Успешная аутентификация
gmod_integration.chat.authentication_failed=Не удалось выполнить аутентификацию
gmod_integration.chat.server_link=, сервер связан как {1}.
gmod_integration.chat.server_fail=, проверьте ваш ID и токен.
gmod_integration.chat.error.screenshot_failed=Не удалось сделать скриншот, возможно, ваша система не поддерживает эту функцию.
gmod_integration.chat.screenshot.sent=Скриншот отправлен в Discord.