0
1
포크 0
원본 프로젝트 nique_372/AiDataTaskRuner
AiDataTaskRuner/UI/Language/LanM.mqh

167 lines
5 KiB
MQL5

2026-03-13 11:50:48 -05:00
//+------------------------------------------------------------------+
//| 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
//---
2026-03-13 16:00:22 -05:00
#define TASKRUNERAI_DEFUALT_LAN (AIDATATASKRUNNER_LAN_ES)
2026-03-13 11:50:48 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CLanguageConfigurator : public CLoggerBase
{
private:
CHashMap<string, string> m_key_to_val;
2026-03-13 15:20:27 -05:00
bool InitInHashMap(const int language);
string m_current_prefix;
2026-03-13 11:50:48 -05:00
public:
CLanguageConfigurator(void) {}
~CLanguageConfigurator(void) {}
//---
2026-03-13 15:20:27 -05:00
bool Init();
void SetLanguageByIndex(const int idx); // idx del langauge
2026-03-13 11:50:48 -05:00
//---
string operator[](const string k)
{
static string v;
2026-03-13 15:20:27 -05:00
return m_key_to_val.TryGetValue(m_current_prefix + "_" + k, v) ? v : NULL;
2026-03-13 11:50:48 -05:00
}
};
//+------------------------------------------------------------------+
2026-03-13 15:20:27 -05:00
//| |
//+------------------------------------------------------------------+
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)
2026-03-13 11:50:48 -05:00
{
//---
const string file = g_aidatatask_runner_langague[language].base_file;
//---
::ResetLastError();
2026-03-13 11:58:57 -05:00
const int fh = FileOpen(file, FILE_READ | FILE_TXT | AIDATATASK_RUNNER_COMON_FLAG);
2026-03-13 11:50:48 -05:00
if(fh == INVALID_HANDLE)
{
LogError(StringFormat("Fallo al abrir el archivo =%s, ultimo error =%d", file, ::GetLastError()), FUNCION_ACTUAL);
return false;
}
2026-03-13 15:20:27 -05:00
//---
const string prefix = string(language);
2026-03-13 11:50:48 -05:00
//---
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;
2026-03-13 15:20:27 -05:00
// Print(str);
2026-03-13 11:50:48 -05:00
//---
int start = StringFindChar(str, '[');
if(start >= 0)
{
2026-03-13 11:58:57 -05:00
start++;
2026-03-13 11:50:48 -05:00
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
2026-03-13 15:20:27 -05:00
//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)))
2026-03-13 11:50:48 -05:00
{
LogError(StringFormat("Fallo al añadir key value, str:\n%s", str), FUNCION_ACTUAL);
}
}
//---
FileClose(fh);
//---
return true;
}
#endif // AIDATATASKRUNER_UI_LANGUAGE_LANM_MQH
//+------------------------------------------------------------------+