Implementar systema de idiomas con gl, es y en

Signed-off-by: somebody_master <somebody_master@somebodyserver.mooo.com>
This commit is contained in:
Somebody Master 2020-10-28 13:26:34 +01:00
parent 275a41a922
commit fbbef585d2
Signed by: somebody_master
GPG Key ID: 78315CFDF0B25505
9 changed files with 240 additions and 19 deletions

View File

@ -29,13 +29,25 @@ add_library(
src/config.cpp 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) add_executable("${PROJECT_NAME}" src/main.cpp)
target_include_directories(ui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_include_directories(ui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_include_directories(configFile 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(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 ui)
target_link_libraries("${PROJECT_NAME}" PRIVATE configFile) target_link_libraries("${PROJECT_NAME}" PRIVATE configFile)
target_link_libraries("${PROJECT_NAME}" PRIVATE ncurses) target_link_libraries("${PROJECT_NAME}" PRIVATE ncurses)
target_link_libraries("${PROJECT_NAME}" PRIVATE config) target_link_libraries("${PROJECT_NAME}" PRIVATE config)
target_link_libraries("${PROJECT_NAME}" PRIVATE textos)

View File

@ -8,10 +8,9 @@ class Config {
public: public:
Config(int8_t numHilos, std::string tiempo); Config(int8_t numHilos, std::string tiempo);
// ~Config();
int8_t getNumHilos(); int8_t getNumHilos();
std::string getTiempo(); std::string getTiempo();
void setNumHilos(int8_t numHilos); void setNumHilos(int8_t numHilos);
void setTiempo(std::string timepo); void setTiempo(std::string tiempo);
}; };
#endif // __CONFIG_HPP_ #endif // __CONFIG_HPP_

25
include/idiomas/en.hpp Normal file
View File

@ -0,0 +1,25 @@
#include <string>
#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_

25
include/idiomas/es.hpp Normal file
View File

@ -0,0 +1,25 @@
#include <string>
#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_

25
include/idiomas/gl.hpp Normal file
View File

@ -0,0 +1,25 @@
#include <string>
#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_

27
include/textos.hpp Normal file
View File

@ -0,0 +1,27 @@
#include <string>
#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_

View File

@ -1,7 +1,8 @@
#include "configFile.hpp"
#include "ui.hpp"
#include <locale.h> #include <locale.h>
#include <thread> #include <thread>
#include "configFile.hpp"
#include "ui.hpp"
#include "textos.hpp"
using namespace std; using namespace std;
@ -37,8 +38,10 @@ void showMenu(vector<string> *menu_elems, const int8_t *num_menu, vector<string>
void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config); void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config);
int main(int argc, char *argv[]) { 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) { if (ui::initUI(&MENU_PRINCIPAL, &MENU_ERROR) != 0) {
return -1; return -1;
} }
@ -48,7 +51,6 @@ int main(int argc, char *argv[]) {
if (config.getTiempo() == "") { if (config.getTiempo() == "") {
userInterface(&PRIMER_INICIO, &config); userInterface(&PRIMER_INICIO, &config);
} else { } else {
userInterface(&MENU_PRINCIPAL, &config); userInterface(&MENU_PRINCIPAL, &config);
} }
@ -65,7 +67,7 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
switch (*num_menu) { switch (*num_menu) {
case CONFIGURAR_MENU_PRINCIPAL: case CONFIGURAR_MENU_PRINCIPAL:
case MENU_PRINCIPAL: { case MENU_PRINCIPAL: {
vector<string> elem_menu = {"- Iniciar Stress Test", "- Configurar", "- Salir"}; vector<string> elem_menu = {txt::g_menuPrincipal_1, txt::g_menuPrincipal_2, txt::g_menuPrincipal_3};
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config); showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config);
break; break;
} }
@ -75,7 +77,7 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
} }
case MENU_CONFIGURACION: { case MENU_CONFIGURACION: {
vector<string> elem_menu = {"- Configurar todo", "- Número de hilos", "- Tiempo", "- Menú principal"}; vector<string> 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); showMenu(&elem_menu, num_menu, mensaje, config);
break; break;
} }
@ -83,8 +85,8 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
case CONFIGURAR_TODO: case CONFIGURAR_TODO:
case PRIMER_INICIO: { case PRIMER_INICIO: {
vector<string> textos_init = {"Toda la configuración se escribirá en " + cf::g_configFile, "", ""}; vector<string> textos_init = {txt::g_confTodo + cf::g_configFile, "", ""};
vector<string> elemens = {"- Número de hilos\t> ", "- Tiempo de ejecución\t> "}; vector<string> elemens = {txt::g_confHilosInput , txt::g_confTiempoInput};
ui::showTopTitle(&TITULO_PRINCIPAL); ui::showTopTitle(&TITULO_PRINCIPAL);
vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size()); vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size());
Config config2 = Config(atoi(entrada[0].c_str()), entrada[1]); Config config2 = Config(atoi(entrada[0].c_str()), entrada[1]);
@ -95,8 +97,8 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
} }
case CONFIGURAR_HILOS: { case CONFIGURAR_HILOS: {
vector<string> textos_init = {"Número de hilos actuales: " + to_string(config->getNumHilos()), "", ""}; vector<string> textos_init = {txt::g_confHilos + to_string(config->getNumHilos()), "", ""};
vector<string> elemens = {"- Número de hilos\t> "}; vector<string> elemens = {txt::g_confHilosInput};
vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size()); vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size());
config->setNumHilos(atoi(entrada[0].c_str())); config->setNumHilos(atoi(entrada[0].c_str()));
cf::saveConfig(config); cf::saveConfig(config);
@ -105,8 +107,8 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
} }
case CONFIGURAR_TIEMPO: { case CONFIGURAR_TIEMPO: {
vector<string> textos_init = {"Tiempo actual" + config->getTiempo(), "", ""}; vector<string> textos_init = {txt::g_confTiempo + config->getTiempo(), "", ""};
vector<string> elemens = {"- Tiempo de ejecución\t> "}; vector<string> elemens = {txt::g_confTiempoInput};
vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size()); vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size());
config->setTiempo(entrada[0]); config->setTiempo(entrada[0]);
cf::saveConfig(config); cf::saveConfig(config);
@ -125,7 +127,7 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
default: { default: {
ui::g_mensaje = true; 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); userInterface(&MENU_PRINCIPAL, mensaje, config);
break; break;
} }
@ -160,12 +162,12 @@ void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config
switch (*num_menu) { switch (*num_menu) {
case MENU_PRINCIPAL: { case MENU_PRINCIPAL: {
mvwprintw(menuwin, 0, 1, "Menú Principal"); mvwprintw(menuwin, 0, 1, txt::g_menuPrincipal.c_str());
break; break;
} }
case MENU_CONFIGURACION: { case MENU_CONFIGURACION: {
mvwprintw(menuwin, 0, 1, "Configuración"); mvwprintw(menuwin, 0, 1, txt::g_menuConfigurar.c_str());
break; break;
} }
} }

105
src/textos.cpp Normal file
View File

@ -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;
}
}

View File

@ -1,5 +1,6 @@
#include "ui.hpp" #include "ui.hpp"
#include "configFile.hpp" #include "configFile.hpp"
#include "textos.hpp"
using namespace std; using namespace std;
@ -16,7 +17,7 @@ int8_t ui::initUI(const int8_t *menu_principal, const int8_t *menu_error) {
noecho(); noecho();
cbreak(); cbreak();
if (!has_colors()) { if (!has_colors()) {
printw("El terminal no soporta colores"); printw(txt::g_noColor.c_str());
getch(); getch();
return -1; return -1;
} }