//+------------------------------------------------------------------+ //| LanM.mqh | //| Copyright 2025, Niquel Mendoza. | //| https://www.mql5.com/es/users/nique_372 | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Niquel Mendoza." #property link "https://www.mql5.com/es/users/nique_372" #property strict #ifndef AIDATATASKRUNER_UI_LANGUAGE_LANM_MQH #define AIDATATASKRUNER_UI_LANGUAGE_LANM_MQH //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "..\\..\\FilesInstaler\\Main.mqh" //--- // Esta clase se encarga de entrenar el nombre de los componenetes //--- #define TASKRUNERAI_DEFUALT_LAN (AIDATATASKRUNNER_LAN_ES) //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CLanguageConfigurator : public CLoggerBase { private: CHashMap m_key_to_val; bool InitInHashMap(const int language); string m_current_prefix; public: CLanguageConfigurator(void) {} ~CLanguageConfigurator(void) {} //--- bool Init(); void SetLanguageByIndex(const int idx); // idx del langauge //--- string operator[](const string k) { static string v; return m_key_to_val.TryGetValue(m_current_prefix + "_" + k, v) ? v : NULL; } }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CLanguageConfigurator::Init(void) { m_current_prefix = string(int(TASKRUNERAI_DEFUALT_LAN)); // Ingles por defecto for(int i = 0; i < AIDATATASKRUNNER_TOTAL_LANGUAGUE; i++) { if(!InitInHashMap(i)) { LogError(StringFormat("Fallo al cargar el idiomar = %s", g_aidatatask_runner_langague_str[i]), FUNCION_ACTUAL); return false; } } //--- return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CLanguageConfigurator::SetLanguageByIndex(const int idx) { m_current_prefix = string(idx); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CLanguageConfigurator::InitInHashMap(const int language) { //--- const string file = g_aidatatask_runner_langague[language].base_file; //--- ::ResetLastError(); const int fh = FileOpen(file, FILE_READ | FILE_TXT | AIDATATASK_RUNNER_COMON_FLAG); if(fh == INVALID_HANDLE) { LogError(StringFormat("Fallo al abrir el archivo =%s, ultimo error =%d", file, ::GetLastError()), FUNCION_ACTUAL); return false; } //--- const string prefix = string(language); //--- string current_class_name = ""; //--- while(!FileIsEnding(fh)) { //--- const string str = FileReadString(fh); //--- const int len = StringLen(str); if(len < 2 || (str[0] == '/' && str[1] == '/')) continue; // Print(str); //--- int start = StringFindChar(str, '['); if(start >= 0) { start++; const int end = StringFindChar(str, ']', start + 1); if(end == -1) { LogWarning("[] Mal formado le falta el ]", FUNCION_ACTUAL); continue; } current_class_name = StringSubstrRange(str, start, end - 1); continue; } //--- Buscamos el = start = StringFindChar(str, '='); if(start == -1) continue; // omitimos //--- Comillas const int sk = StringFindChar(str, '"', start + 1); if(sk == -1) { LogWarning("No se encontro la comilla de inicio", FUNCION_ACTUAL); continue; } const int ek = StringFindAtras(str, '"'); if(sk == -1) { LogWarning("No se encontro la comilla de fin", FUNCION_ACTUAL); continue; } //--- Añaidmos el key value //Print(StringSubstrRange(str, sk, ek)); // Print(current_class_name + "_" + StringSubstr(str, 0, start)); if(!m_key_to_val.Add(prefix + "_" + current_class_name + "_" + StringSubstr(str, 0, start), StringSubstrRange(str, sk + 1, ek - 1))) { LogError(StringFormat("Fallo al añadir key value, str:\n%s", str), FUNCION_ACTUAL); } } //--- FileClose(fh); //--- return true; } #endif // AIDATATASKRUNER_UI_LANGUAGE_LANM_MQH //+------------------------------------------------------------------+