diff --git a/lua/gmod_integration/client/cl_context_menu.lua b/lua/gmod_integration/client/cl_context_menu.lua index 16c8ae5..ee77b2c 100644 --- a/lua/gmod_integration/client/cl_context_menu.lua +++ b/lua/gmod_integration/client/cl_context_menu.lua @@ -12,7 +12,7 @@ list.Set("DesktopWindows", "GmodIntegration:DesktopWindows", { list.Set("DesktopWindows", "GmodIntegration:DesktopWindows:ReportBug", { 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, height = 700, onewindow = true, diff --git a/lua/gmod_integration/client/cl_main.lua b/lua/gmod_integration/client/cl_main.lua index 70e5ea6..29f5ece 100644 --- a/lua/gmod_integration/client/cl_main.lua +++ b/lua/gmod_integration/client/cl_main.lua @@ -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 = {} 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) end - chat.AddText(unpack(args)) + gmInte.chatAddText(unpack(args)) end function gmInte.showTestConnection(data) 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 - 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 function gmInte.openAdminConfig() 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 end diff --git a/lua/gmod_integration/client/cl_net.lua b/lua/gmod_integration/client/cl_net.lua index a300e82..4467f83 100644 --- a/lua/gmod_integration/client/cl_net.lua +++ b/lua/gmod_integration/client/cl_net.lua @@ -25,7 +25,7 @@ local netReceive = { gmInte.version = data.other.version if !data.other.aprovedCredentials then RunConsoleCommand("gmod_integration_admin") end end, - [6] = function(data) gmInte.chatAddText(data) end, + [6] = function(data) gmInte.chatAddTextFromTable(data) end, [7] = function() gmInte.openVerifPopup() end, [8] = function(data) gmInte.config.token = data.token end } diff --git a/lua/gmod_integration/client/cl_report_bug.lua b/lua/gmod_integration/client/cl_report_bug.lua index 4bd042d..7875ac5 100644 --- a/lua/gmod_integration/client/cl_report_bug.lua +++ b/lua/gmod_integration/client/cl_report_bug.lua @@ -1,46 +1,49 @@ local Fields = { { - ["title"] = language.GetPhrase("gmod_integration.report_bug.title", "Report a bug"), + ["title"] = gmInte.getTranslation("report_bug.title", "Report a bug"), ["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", - ["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, }, { - ["title"] = language.GetPhrase("gmod_integration.report_bug.importance_level", "Importance Level"), + ["title"] = gmInte.getTranslation("report_bug.importance_level", "Importance Level"), ["type"] = "dropdown", ["options"] = { - ["critical"] = language.GetPhrase("gmod_integration.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."), - ["medium"] = language.GetPhrase("gmod_integration.report_bug.importance_level.medium", "Medium - Important functionality is unusable."), - ["low"] = language.GetPhrase("gmod_integration.report_bug.importance_level.low", "Low - Cosmetic issue."), - ["trivial"] = language.GetPhrase("gmod_integration.report_bug.importance_level.trivial", "Trivial - Very minor issue."), + ["critical"] = gmInte.getTranslation("report_bug.importance_level.critical", "Critical - Crash or made the game unplayable."), + ["high"] = gmInte.getTranslation("report_bug.importance_level.high", "High - Critical functionality is unusable."), + ["medium"] = gmInte.getTranslation("report_bug.importance_level.medium", "Medium - Important functionality is unusable."), + ["low"] = gmInte.getTranslation("report_bug.importance_level.low", "Low - Cosmetic 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", - ["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, }, { - ["title"] = language.GetPhrase("gmod_integration.report_bug.expected_result", "Expected result"), + ["title"] = gmInte.getTranslation("report_bug.expected_result", "Expected result"), ["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, }, { - ["title"] = language.GetPhrase("gmod_integration.report_bug.actual_result", "Actual result"), + ["title"] = gmInte.getTranslation("report_bug.actual_result", "Actual result"), ["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, }, } -function gmInte.openReportBug() +local ScreenshotRequested = false +hook.Add("PostRender", "gmInte:BugReport:Screenshot", function() + if !ScreenshotRequested then return end + ScreenshotRequested = false local captureData = { format = "jpeg", x = 0, @@ -52,10 +55,31 @@ function gmInte.openReportBug() local screenCapture = render.Capture(captureData) 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") frame:SetSize(500, (700 / 1080) * ScrH()) 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() gmInte.applyPaint(frame) // bug report = screenshot, description, steps to reproduce, expected result, actual result @@ -65,7 +89,6 @@ function gmInte.openReportBug() local elements = {} for _ = 1, #Fields do local field = Fields[_] - if field.type == "image" && !screenCapture then continue end local label = vgui.Create("DLabel", dPanel) label:Dock(TOP) label:DockMargin(5, 5, 5, 5) @@ -89,7 +112,7 @@ function gmInte.openReportBug() local dropdown = vgui.Create("DComboBox", dPanel) dropdown:Dock(TOP) 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 dropdown:AddChoice(value, key) end @@ -119,7 +142,7 @@ function gmInte.openReportBug() if !elements[4]:GetText() || elements[4]:GetText() == "" then readyForSend = false end if !elements[5]:GetText() || elements[5]:GetText() == "" then readyForSend = false end 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 end @@ -144,9 +167,9 @@ function gmInte.openReportBug() ["expected"] = elements[4]:GetText(), ["actual"] = elements[5]:GetText(), }, 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() - 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 diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua index e3f97b7..618d847 100644 --- a/lua/gmod_integration/client/cl_screenshots.lua +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -23,7 +23,7 @@ hook.Add("PostRender", "gmInteScreenshot", function() return else 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 end end @@ -36,10 +36,7 @@ hook.Add("PostRender", "gmInteScreenshot", function() ["screenshot"] = base64Capture, ["captureData"] = captureData, ["size"] = size .. "KB" - }, function(code, body) - 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) + }, 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) end) function gmInte.takeScreenShot() diff --git a/resource/localization/de/gmod_integration.properties b/resource/localization/de/gmod_integration.properties index 2022535..a50312b 100644 --- a/resource/localization/de/gmod_integration.properties +++ b/resource/localization/de/gmod_integration.properties @@ -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.success=Fehlerbericht erfolgreich gesendet 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. \ No newline at end of file diff --git a/resource/localization/en/gmod_integration.properties b/resource/localization/en/gmod_integration.properties index 659fc50..a57b911 100644 --- a/resource/localization/en/gmod_integration.properties +++ b/resource/localization/en/gmod_integration.properties @@ -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.success=Bug report sent successfully 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. \ No newline at end of file diff --git a/resource/localization/es/gmod_integration.properties b/resource/localization/es/gmod_integration.properties index f274055..1677979 100644 --- a/resource/localization/es/gmod_integration.properties +++ b/resource/localization/es/gmod_integration.properties @@ -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.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.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. \ No newline at end of file diff --git a/resource/localization/fr/gmod_integration.properties b/resource/localization/fr/gmod_integration.properties index b628e75..60677d2 100644 --- a/resource/localization/fr/gmod_integration.properties +++ b/resource/localization/fr/gmod_integration.properties @@ -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.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.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. \ No newline at end of file diff --git a/resource/localization/ru/gmod_integration.properties b/resource/localization/ru/gmod_integration.properties index c3c376d..b888efb 100644 --- a/resource/localization/ru/gmod_integration.properties +++ b/resource/localization/ru/gmod_integration.properties @@ -22,3 +22,10 @@ gmod_integration.report_bug.description.dsc=Пожалуйста, предост gmod_integration.report_bug.error.missing_fields=Перед отправкой отчета об ошибке, заполните все обязательные поля. gmod_integration.report_bug.success=Отчет об ошибке успешно отправлен 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. \ No newline at end of file