diff options
| author | garder500 <jeremy27.clara22@gmail.com> | 2025-05-01 17:25:14 +0200 |
|---|---|---|
| committer | garder500 <jeremy27.clara22@gmail.com> | 2025-05-01 17:25:14 +0200 |
| commit | 1aa7ec4539170739986bcbb4d542f5432f98bea5 (patch) | |
| tree | d66322220c7a585a22be4261c96633ac6e2b4f8c /bot/src/utils.cpp | |
| parent | 6c4647611317e27e38d70bfbc55eb180bc377809 (diff) | |
Ajout de la gestion des traductions et des messages d'erreur en plusieurs langues, suppression des fichiers de traduction obsolètes.
Diffstat (limited to 'bot/src/utils.cpp')
| -rw-r--r-- | bot/src/utils.cpp | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/bot/src/utils.cpp b/bot/src/utils.cpp index 349f584..18c43b5 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,39 @@ namespace app } return str; } + + std::string get_available_locale(std::string locale) + { + std::vector<std::string> available_locales = {"en", "fr"}; + std::string lang = locale.substr(0, 2); + std::transform(lang.begin(), lang.end(), lang.begin(), ::tolower); + if (std::find(available_locales.begin(), available_locales.end(), lang) != available_locales.end()) + { + return lang; + } + else + { + return "en"; // Default to English if not 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 lang = get_available_locale(locale); + auto it = array_translations.find(Lang::en); + 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 + } } |
