summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgarder500 <jeremy27.clara22@gmail.com>2025-05-02 00:10:43 +0200
committergarder500 <jeremy27.clara22@gmail.com>2025-05-02 00:10:43 +0200
commit83298ee3aec687ba1c5f41fb7135e465869d4fe8 (patch)
treed4d54cd1f1cb8d6e355fee138cf0d460dd4b1b6f
parentfe156854748a767aafc773748e1c4ecc9a701484 (diff)
Refactor la gestion des traductions : remplacement des maps par des unordered_maps pour améliorer les performances dans la fonction translate.
-rw-r--r--bot/include/utils.hpp5
-rw-r--r--bot/src/actions/delete.cpp2
-rw-r--r--bot/src/utils.cpp2
3 files changed, 3 insertions, 6 deletions
diff --git a/bot/include/utils.hpp b/bot/include/utils.hpp
index b0482dd..7008dec 100644
--- a/bot/include/utils.hpp
+++ b/bot/include/utils.hpp
@@ -1,7 +1,5 @@
// utils.hpp
#pragma once
-#ifndef UTILS_HPP
-#define UTILS_HPP
#include <dpp/dpp.h>
#include <dpp/nlohmann/json.hpp>
@@ -103,10 +101,9 @@ namespace app
* @param args The optional parameters to replace in the string
* @return std::string The translated string
*/
- std::string translate(const std::string &str, const std::string &locale, const std::map<Lang, std::map<std::string, std::string>> &array_translations, const std::unordered_map<std::string, std::string> &args = {});
+ std::string translate(const std::string &str, const std::string &locale, const std::unordered_map<Lang, std::unordered_map<std::string, std::string>> &array_translations, const std::unordered_map<std::string, std::string> &args = {});
} // namespace dpp
-#endif // UTILS_HPP
// utils.hpp
diff --git a/bot/src/actions/delete.cpp b/bot/src/actions/delete.cpp
index dbd9efe..da74bbf 100644
--- a/bot/src/actions/delete.cpp
+++ b/bot/src/actions/delete.cpp
@@ -1,7 +1,7 @@
#include "../../include/utils.hpp"
-const std::map<Lang, std::map<std::string, std::string>> error_messages_map = {
+const std::unordered_map<Lang, std::unordered_map<std::string, std::string>> error_messages_map = {
{Lang::en, {
{"error_no_messages", "No message to delete."},
{"error", "You need to wait a bit before deleting messages."},
diff --git a/bot/src/utils.cpp b/bot/src/utils.cpp
index 3ad1bad..a2ce928 100644
--- a/bot/src/utils.cpp
+++ b/bot/src/utils.cpp
@@ -218,7 +218,7 @@ namespace app
return Lang::en; // Default to English if no match is found
}
- std::string translate(const std::string &str, const std::string &locale, const std::map<Lang, std::map<std::string, std::string>> &array_translations, const std::unordered_map<std::string, std::string> &args)
+ std::string translate(const std::string &str, const std::string &locale, const std::unordered_map<Lang, std::unordered_map<std::string, std::string>> &array_translations, const std::unordered_map<std::string, std::string> &args)
{
Lang lang = get_available_locale(locale);
auto it = array_translations.find(lang);