summaryrefslogtreecommitdiff
path: root/bot/src/utils.cpp
diff options
context:
space:
mode:
authorsoler_j <soler_j@etna-alternance.net>2025-05-04 01:26:36 +0200
committersoler_j <soler_j@etna-alternance.net>2025-05-04 01:26:36 +0200
commite82d081f0fc630fe9244ff9d461f91dd1d4dc63b (patch)
tree09c49fec114326a982648ccb4ce961f092a44b19 /bot/src/utils.cpp
parent23cba7cd6b32b7c5db98aa5a3f9206d4bce07902 (diff)
parent502ae25637f103a063c145509c051d1ce6061e4f (diff)
Merge branch '1-more-actions-to-handle' of github.com:ketsuna-org/bot-creator-api into 1-more-actions-to-handle
Diffstat (limited to 'bot/src/utils.cpp')
-rw-r--r--bot/src/utils.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/bot/src/utils.cpp b/bot/src/utils.cpp
index 349f584..a2ce928 100644
--- a/bot/src/utils.cpp
+++ b/bot/src/utils.cpp
@@ -1,10 +1,4 @@
-#include <dpp/dpp.h>
-#include <dpp/nlohmann/json.hpp>
-#include <map>
-#include <string>
-#include <regex>
-#include <sstream>
-#include <algorithm>
+#include "../include/utils.hpp"
using namespace dpp;
namespace app
@@ -212,4 +206,35 @@ namespace app
}
return str;
}
+
+ Lang get_available_locale(std::string locale)
+ {
+ std::transform(locale.begin(), locale.end(), locale.begin(), ::tolower);
+ if (locale == "fr" || locale == "fr-fr")
+ return Lang::fr;
+ else if (locale == "en" || locale == "en-us")
+ return Lang::en;
+ else
+ return Lang::en; // Default to English if no match is found
+ }
+
+ 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);
+ if (it != array_translations.end())
+ {
+ auto it2 = it->second.find(str);
+ if (it2 != it->second.end())
+ {
+ std::string translation = it2->second;
+ for (const auto &arg : args)
+ {
+ translation = update_string(translation, args);
+ }
+ return translation;
+ }
+ }
+ return str; // Return the original string if no translation is found
+ }
}