From fbbef585d253342c13c6db4e7938623a488d5c80 Mon Sep 17 00:00:00 2001 From: somebody_master Date: Wed, 28 Oct 2020 13:26:34 +0100 Subject: [PATCH] Implementar systema de idiomas con gl, es y en Signed-off-by: somebody_master --- CMakeLists.txt | 12 +++++ include/config.hpp | 3 +- include/idiomas/en.hpp | 25 ++++++++++ include/idiomas/es.hpp | 25 ++++++++++ include/idiomas/gl.hpp | 25 ++++++++++ include/textos.hpp | 27 +++++++++++ src/main.cpp | 34 ++++++------- src/textos.cpp | 105 +++++++++++++++++++++++++++++++++++++++++ src/ui.cpp | 3 +- 9 files changed, 240 insertions(+), 19 deletions(-) create mode 100644 include/idiomas/en.hpp create mode 100644 include/idiomas/es.hpp create mode 100644 include/idiomas/gl.hpp create mode 100644 include/textos.hpp create mode 100644 src/textos.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 23231ed..922e799 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,13 +29,25 @@ add_library( src/config.cpp ) +add_library( + textos + include/textos.hpp + src/textos.cpp + include/idiomas/es.hpp + include/idiomas/gl.hpp + include/idiomas/en.hpp + ) + add_executable("${PROJECT_NAME}" src/main.cpp) target_include_directories(ui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_include_directories(configFile PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_include_directories(config PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_include_directories(textos PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") +#target_include_directories(textos PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/textos") target_link_libraries("${PROJECT_NAME}" PRIVATE ui) target_link_libraries("${PROJECT_NAME}" PRIVATE configFile) target_link_libraries("${PROJECT_NAME}" PRIVATE ncurses) target_link_libraries("${PROJECT_NAME}" PRIVATE config) +target_link_libraries("${PROJECT_NAME}" PRIVATE textos) diff --git a/include/config.hpp b/include/config.hpp index cf77040..912fb4f 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -8,10 +8,9 @@ class Config { public: Config(int8_t numHilos, std::string tiempo); - // ~Config(); int8_t getNumHilos(); std::string getTiempo(); void setNumHilos(int8_t numHilos); - void setTiempo(std::string timepo); + void setTiempo(std::string tiempo); }; #endif // __CONFIG_HPP_ diff --git a/include/idiomas/en.hpp b/include/idiomas/en.hpp new file mode 100644 index 0000000..8e40a44 --- /dev/null +++ b/include/idiomas/en.hpp @@ -0,0 +1,25 @@ +#include +#ifndef __EN_HPP_ +#define __EN_HPP_ + +namespace en{ + const extern std::string noColor = "The terminal doesn't support cors"; + const extern std::string errorGenerico_1 = "How do you get here?"; + const extern std::string errorGenerico_2 = "Just in case we go to the main menu"; + const extern std::string menuPrincipal = "Main Menu"; + const extern std::string menuPrincipal_1 = "- Start Stress Test"; + const extern std::string menuPrincipal_2 = "- Configurate"; + const extern std::string menuPrincipal_3 = "- Exit"; + const extern std::string menuConfigurar = "Configuration"; + const extern std::string menuConfigurar_1 = "- Configurate all"; + const extern std::string menuConfigurar_2 = "- Number of threads"; + const extern std::string menuConfigurar_3 = "- Time"; + const extern std::string menuConfigurar_4 = "- Main Menu"; + const extern std::string confTodo = "All the configuration will be write in "; + const extern std::string confHilos = "Current number of threads > "; + const extern std::string confTiempo = "Current execution time > "; + const extern std::string confHilosInput = "- Number of threads\t> "; + const extern std::string confTiempoInput = "- Execution time\t> "; +} + +#endif // __EN_HPP_ diff --git a/include/idiomas/es.hpp b/include/idiomas/es.hpp new file mode 100644 index 0000000..83183d6 --- /dev/null +++ b/include/idiomas/es.hpp @@ -0,0 +1,25 @@ +#include +#ifndef __ES_HPP_ +#define __ES_HPP_ + +namespace es{ + const extern std::string noColor = "El terminal no soporta colores"; + const extern std::string errorGenerico_1 = "¿Como has llegado aquí?"; + const extern std::string errorGenerico_2 = "Por si acaso vamos al menú principal"; + const extern std::string menuPrincipal = "Menú Principal"; + const extern std::string menuPrincipal_1 = "- Iniciar Stress Test"; + const extern std::string menuPrincipal_2 = "- Configurar"; + const extern std::string menuPrincipal_3 = "- Salir"; + const extern std::string menuConfigurar = "Configuración"; + const extern std::string menuConfigurar_1 = "- Configurar todo"; + const extern std::string menuConfigurar_2 = "- Número de hilos"; + const extern std::string menuConfigurar_3 = "- Tiempo"; + const extern std::string menuConfigurar_4 = "- Menú principal"; + const extern std::string confTodo = "Toda la configuración se escribirá en "; + const extern std::string confHilos = "Número de hilos actuales > "; + const extern std::string confTiempo = "Tiempo actual > "; + const extern std::string confHilosInput = "- Número de hilos\t> "; + const extern std::string confTiempoInput = "- Tiempo de ejecución\t> "; +} + +#endif // __ES_HPP_ diff --git a/include/idiomas/gl.hpp b/include/idiomas/gl.hpp new file mode 100644 index 0000000..599db77 --- /dev/null +++ b/include/idiomas/gl.hpp @@ -0,0 +1,25 @@ +#include +#ifndef __GL_HPP_ +#define __GL_HPP_ + +namespace gl{ + const extern std::string noColor = "El terminal non soporta cores"; + const extern std::string errorGenerico_1 = "Como chegaches aquí?"; + const extern std::string errorGenerico_2 = "Por si acaso imos ó menú principal"; + const extern std::string menuPrincipal = "Menú Principal"; + const extern std::string menuPrincipal_1 = "- Iniciar Stress Test"; + const extern std::string menuPrincipal_2 = "- Configurar"; + const extern std::string menuPrincipal_3 = "- Sair"; + const extern std::string menuConfigurar = "Configuración"; + const extern std::string menuConfigurar_1 = "- Configurar todo"; + const extern std::string menuConfigurar_2 = "- Número de filos"; + const extern std::string menuConfigurar_3 = "- Tempo"; + const extern std::string menuConfigurar_4 = "- Menú principal"; + const extern std::string confTodo = "Toda a configuración escribirase en "; + const extern std::string confHilos = "Número de filos actuáis > "; + const extern std::string confTiempo = "Tempo actual > "; + const extern std::string confHilosInput = "- Número de filos\t> "; + const extern std::string confTiempoInput = "- Tempo de execución\t> "; +} + +#endif // __GL_HPP_ diff --git a/include/textos.hpp b/include/textos.hpp new file mode 100644 index 0000000..8aae4bf --- /dev/null +++ b/include/textos.hpp @@ -0,0 +1,27 @@ +#include +#ifndef __TEXTOS_HPP_ +#define __TEXTOS_HPP_ + +namespace txt{ + extern std::string g_noColor; + extern std::string g_errorGenerico_1; + extern std::string g_errorGenerico_2; + extern std::string g_menuPrincipal; + extern std::string g_menuPrincipal_1; + extern std::string g_menuPrincipal_2; + extern std::string g_menuPrincipal_3; + extern std::string g_menuConfigurar; + extern std::string g_menuConfigurar_1; + extern std::string g_menuConfigurar_2; + extern std::string g_menuConfigurar_3; + extern std::string g_menuConfigurar_4; + extern std::string g_confTodo; + extern std::string g_confHilos; + extern std::string g_confTiempo; + extern std::string g_confHilosInput; + extern std::string g_confTiempoInput; + + void inicializarIdioma(std::string idioma); +} + +#endif // __TEXTOS_HPP_ diff --git a/src/main.cpp b/src/main.cpp index be11581..f57f5f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,8 @@ -#include "configFile.hpp" -#include "ui.hpp" #include #include +#include "configFile.hpp" +#include "ui.hpp" +#include "textos.hpp" using namespace std; @@ -37,8 +38,10 @@ void showMenu(vector *menu_elems, const int8_t *num_menu, vector void showMenu(vector *menu_elems, const int8_t *num_menu, Config *config); int main(int argc, char *argv[]) { - // locale::global(locale("es_ES.utf8")); - setlocale(LC_ALL, ""); + + string idioma = setlocale(LC_ALL, ""); + txt::inicializarIdioma(idioma); + if (ui::initUI(&MENU_PRINCIPAL, &MENU_ERROR) != 0) { return -1; } @@ -48,7 +51,6 @@ int main(int argc, char *argv[]) { if (config.getTiempo() == "") { userInterface(&PRIMER_INICIO, &config); } else { - userInterface(&MENU_PRINCIPAL, &config); } @@ -65,7 +67,7 @@ void userInterface(const int8_t *num_menu, vector *mensaje, Config *conf switch (*num_menu) { case CONFIGURAR_MENU_PRINCIPAL: case MENU_PRINCIPAL: { - vector elem_menu = {"- Iniciar Stress Test", "- Configurar", "- Salir"}; + vector elem_menu = {txt::g_menuPrincipal_1, txt::g_menuPrincipal_2, txt::g_menuPrincipal_3}; showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config); break; } @@ -75,7 +77,7 @@ void userInterface(const int8_t *num_menu, vector *mensaje, Config *conf } case MENU_CONFIGURACION: { - vector elem_menu = {"- Configurar todo", "- Número de hilos", "- Tiempo", "- Menú principal"}; + vector elem_menu = {txt::g_menuConfigurar_1, txt::g_menuConfigurar_2, txt::g_menuConfigurar_3, txt::g_menuConfigurar_4}; showMenu(&elem_menu, num_menu, mensaje, config); break; } @@ -83,8 +85,8 @@ void userInterface(const int8_t *num_menu, vector *mensaje, Config *conf case CONFIGURAR_TODO: case PRIMER_INICIO: { - vector textos_init = {"Toda la configuración se escribirá en " + cf::g_configFile, "", ""}; - vector elemens = {"- Número de hilos\t> ", "- Tiempo de ejecución\t> "}; + vector textos_init = {txt::g_confTodo + cf::g_configFile, "", ""}; + vector elemens = {txt::g_confHilosInput , txt::g_confTiempoInput}; ui::showTopTitle(&TITULO_PRINCIPAL); vector entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size()); Config config2 = Config(atoi(entrada[0].c_str()), entrada[1]); @@ -95,8 +97,8 @@ void userInterface(const int8_t *num_menu, vector *mensaje, Config *conf } case CONFIGURAR_HILOS: { - vector textos_init = {"Número de hilos actuales: " + to_string(config->getNumHilos()), "", ""}; - vector elemens = {"- Número de hilos\t> "}; + vector textos_init = {txt::g_confHilos + to_string(config->getNumHilos()), "", ""}; + vector elemens = {txt::g_confHilosInput}; vector entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size()); config->setNumHilos(atoi(entrada[0].c_str())); cf::saveConfig(config); @@ -105,8 +107,8 @@ void userInterface(const int8_t *num_menu, vector *mensaje, Config *conf } case CONFIGURAR_TIEMPO: { - vector textos_init = {"Tiempo actual" + config->getTiempo(), "", ""}; - vector elemens = {"- Tiempo de ejecución\t> "}; + vector textos_init = {txt::g_confTiempo + config->getTiempo(), "", ""}; + vector elemens = {txt::g_confTiempoInput}; vector entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size()); config->setTiempo(entrada[0]); cf::saveConfig(config); @@ -125,7 +127,7 @@ void userInterface(const int8_t *num_menu, vector *mensaje, Config *conf default: { ui::g_mensaje = true; - *mensaje = {"¿Como has llegado aquí?", "Por si acaso vamos al menú principal"}; + *mensaje = {txt::g_errorGenerico_1, txt::g_errorGenerico_2}; userInterface(&MENU_PRINCIPAL, mensaje, config); break; } @@ -160,12 +162,12 @@ void showMenu(vector *menu_elems, const int8_t *num_menu, Config *config switch (*num_menu) { case MENU_PRINCIPAL: { - mvwprintw(menuwin, 0, 1, "Menú Principal"); + mvwprintw(menuwin, 0, 1, txt::g_menuPrincipal.c_str()); break; } case MENU_CONFIGURACION: { - mvwprintw(menuwin, 0, 1, "Configuración"); + mvwprintw(menuwin, 0, 1, txt::g_menuConfigurar.c_str()); break; } } diff --git a/src/textos.cpp b/src/textos.cpp new file mode 100644 index 0000000..7ce16e7 --- /dev/null +++ b/src/textos.cpp @@ -0,0 +1,105 @@ +#include "textos.hpp" +#include "idiomas/es.hpp" +#include "idiomas/gl.hpp" +#include "idiomas/en.hpp" + +std::string txt::g_noColor = ""; +std::string txt::g_errorGenerico_1 = ""; +std::string txt::g_errorGenerico_2 = ""; +std::string txt::g_menuPrincipal = ""; +std::string txt::g_menuPrincipal_1 = ""; +std::string txt::g_menuPrincipal_2 = ""; +std::string txt::g_menuPrincipal_3 = ""; +std::string txt::g_menuConfigurar = ""; +std::string txt::g_menuConfigurar_1 = ""; +std::string txt::g_menuConfigurar_2 = ""; +std::string txt::g_menuConfigurar_3 = ""; +std::string txt::g_menuConfigurar_4 = ""; +std::string txt::g_confTodo = ""; +std::string txt::g_confHilos = ""; +std::string txt::g_confTiempo = ""; +std::string txt::g_confHilosInput = ""; +std::string txt::g_confTiempoInput = ""; + +void txt::inicializarIdioma(std::string idioma){ + idioma = idioma.substr(0, idioma.find(".")); + + if(idioma == "gl_ES"){ + using namespace gl; + txt::g_noColor = noColor; + txt::g_errorGenerico_1 = errorGenerico_1; + txt::g_errorGenerico_2 = errorGenerico_2; + txt::g_menuPrincipal = menuPrincipal; + txt::g_menuPrincipal_1 = menuPrincipal_1; + txt::g_menuPrincipal_2 = menuPrincipal_2; + txt::g_menuPrincipal_3 = menuPrincipal_3; + txt::g_menuConfigurar = menuConfigurar; + txt::g_menuConfigurar_1 = menuConfigurar_1; + txt::g_menuConfigurar_2 = menuConfigurar_2; + txt::g_menuConfigurar_3 = menuConfigurar_3; + txt::g_menuConfigurar_4 = menuConfigurar_4; + txt::g_confTodo = confTodo; + txt::g_confHilos = confHilos; + txt::g_confTiempo = confTiempo; + txt::g_confHilosInput = confHilosInput; + txt::g_confTiempoInput = confTiempoInput; + }else if(idioma == "es_ES"){ + using namespace es; + txt::g_noColor = noColor; + txt::g_errorGenerico_1 = errorGenerico_1; + txt::g_errorGenerico_2 = errorGenerico_2; + txt::g_menuPrincipal = menuPrincipal; + txt::g_menuPrincipal_1 = menuPrincipal_1; + txt::g_menuPrincipal_2 = menuPrincipal_2; + txt::g_menuPrincipal_3 = menuPrincipal_3; + txt::g_menuConfigurar = menuConfigurar; + txt::g_menuConfigurar_1 = menuConfigurar_1; + txt::g_menuConfigurar_2 = menuConfigurar_2; + txt::g_menuConfigurar_3 = menuConfigurar_3; + txt::g_menuConfigurar_4 = menuConfigurar_4; + txt::g_confTodo = confTodo; + txt::g_confHilos = confHilos; + txt::g_confTiempo = confTiempo; + txt::g_confHilosInput = confHilosInput; + txt::g_confTiempoInput = confTiempoInput; + }else if(idioma == "en_US" || idioma == "en_EN"){ + using namespace en; + txt::g_noColor = noColor; + txt::g_errorGenerico_1 = errorGenerico_1; + txt::g_errorGenerico_2 = errorGenerico_2; + txt::g_menuPrincipal = menuPrincipal; + txt::g_menuPrincipal_1 = menuPrincipal_1; + txt::g_menuPrincipal_2 = menuPrincipal_2; + txt::g_menuPrincipal_3 = menuPrincipal_3; + txt::g_menuConfigurar = menuConfigurar; + txt::g_menuConfigurar_1 = menuConfigurar_1; + txt::g_menuConfigurar_2 = menuConfigurar_2; + txt::g_menuConfigurar_3 = menuConfigurar_3; + txt::g_menuConfigurar_4 = menuConfigurar_4; + txt::g_confTodo = confTodo; + txt::g_confHilos = confHilos; + txt::g_confTiempo = confTiempo; + txt::g_confHilosInput = confHilosInput; + txt::g_confTiempoInput = confTiempoInput; + }else{ + using namespace en; + txt::g_noColor = noColor; + txt::g_errorGenerico_1 = errorGenerico_1; + txt::g_errorGenerico_2 = errorGenerico_2; + txt::g_menuPrincipal = menuPrincipal; + txt::g_menuPrincipal_1 = menuPrincipal_1; + txt::g_menuPrincipal_2 = menuPrincipal_2; + txt::g_menuPrincipal_3 = menuPrincipal_3; + txt::g_menuConfigurar = menuConfigurar; + txt::g_menuConfigurar_1 = menuConfigurar_1; + txt::g_menuConfigurar_2 = menuConfigurar_2; + txt::g_menuConfigurar_3 = menuConfigurar_3; + txt::g_menuConfigurar_4 = menuConfigurar_4; + txt::g_confTodo = confTodo; + txt::g_confHilos = confHilos; + txt::g_confTiempo = confTiempo; + txt::g_confHilosInput = confHilosInput; + txt::g_confTiempoInput = confTiempoInput; + } + +} diff --git a/src/ui.cpp b/src/ui.cpp index de565cf..4615bb7 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1,5 +1,6 @@ #include "ui.hpp" #include "configFile.hpp" +#include "textos.hpp" using namespace std; @@ -16,7 +17,7 @@ int8_t ui::initUI(const int8_t *menu_principal, const int8_t *menu_error) { noecho(); cbreak(); if (!has_colors()) { - printw("El terminal no soporta colores"); + printw(txt::g_noColor.c_str()); getch(); return -1; }