From 1aa7ec4539170739986bcbb4d542f5432f98bea5 Mon Sep 17 00:00:00 2001 From: garder500 Date: Thu, 1 May 2025 17:25:14 +0200 Subject: Ajout de la gestion des traductions et des messages d'erreur en plusieurs langues, suppression des fichiers de traduction obsolètes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/src/utils.cpp | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'bot/src/utils.cpp') 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 -#include -#include -#include -#include -#include -#include +#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 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> &array_translations, const std::unordered_map &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 + } } -- cgit v1.2.3