From 426fb451705d646f7836d06771f3b4fd931afe93 Mon Sep 17 00:00:00 2001 From: Pascal Brunot Date: Sat, 4 May 2024 14:08:32 +0200 Subject: [PATCH] Added translations for portal text And removed FABLAB_* for FABOMATIC_* CppLinter fixes --- include/language/en-US.hpp | 8 +++++++- include/language/it-IT.hpp | 7 ++++++- include/language/lang.hpp | 11 ++++++----- platformio.ini | 12 ++++++------ src/main.cpp | 9 +++++---- src/mock/MockMQTTBroker.cpp | 8 +++----- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/include/language/en-US.hpp b/include/language/en-US.hpp index 0d36dde2..18ecabb7 100644 --- a/include/language/en-US.hpp +++ b/include/language/en-US.hpp @@ -61,5 +61,11 @@ namespace fabomatic::strings::en_US static constexpr auto FACTORY_RESET_DONE_1 = "Factory reset"; static constexpr auto FACTORY_RESET_DONE_2 = "Wait reboot"; -} + static constexpr auto PORTAL_TITLE = "FAB-O-MATIC"; + static constexpr auto PORTAL_MACHINE_ID_PROMPT = "Machine ID"; + static constexpr auto PORTAL_SHELLY_MQTT_PROMPT = "Shelly MQTT topic (can be empty)"; + static constexpr auto PORTAL_MQTT_BROKER_PROMPT = "MQTT broker (IP or hostname)"; + +} // namespace fabomatic::strings::en_US + #endif \ No newline at end of file diff --git a/include/language/it-IT.hpp b/include/language/it-IT.hpp index cd2a9ccd..b568e429 100644 --- a/include/language/it-IT.hpp +++ b/include/language/it-IT.hpp @@ -61,5 +61,10 @@ namespace fabomatic::strings::it_IT static constexpr auto FACTORY_RESET_DONE_1 = "Param. reset"; static constexpr auto FACTORY_RESET_DONE_2 = "Attesa reboot"; -} + static constexpr auto PORTAL_TITLE = "FAB-O-MATIC"; + static constexpr auto PORTAL_MACHINE_ID_PROMPT = "ID della macchina"; + static constexpr auto PORTAL_SHELLY_MQTT_PROMPT = "Topic MQTT per Shelly (facoltativo)"; + static constexpr auto PORTAL_MQTT_BROKER_PROMPT = "Indirizzo o nome MQTT broker"; +} // namespace fabomatic::strings::it_IT + #endif \ No newline at end of file diff --git a/include/language/lang.hpp b/include/language/lang.hpp index c356141c..7c0be565 100644 --- a/include/language/lang.hpp +++ b/include/language/lang.hpp @@ -1,8 +1,8 @@ -#ifndef _LANGUAGE_LANG_HPP -#define _LANGUAGE_LANG_HPP +#ifndef _FABOMATIC_LANG_HPP +#define _FABOMATIC_LANG_HPP // Include Italian language -#if FABLAB_LANG_IT_IT +#if FABOMATIC_LANG_IT_IT #include "language/it-IT.hpp" namespace fabomatic::strings { @@ -11,7 +11,7 @@ namespace fabomatic::strings #endif // Include English language -#ifdef FABLAB_LANG_EN_US +#ifdef FABOMATIC_LANG_EN_US #include "language/en-US.hpp" namespace fabomatic::strings { @@ -20,4 +20,5 @@ namespace fabomatic::strings #endif // Repeat the pattern above if other languages are needed -#endif \ No newline at end of file + +#endif // _FABOMATIC_LANG_HPP \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 50b98085..63fd029a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -69,7 +69,7 @@ build_src_flags = ${env.build_src_flags} -D RFID_SIMULATION=false -D PINS_ESP32S3 -D DEBUG - -D FABLAB_LANG_IT_IT + -D FABOMATIC_LANG_IT_IT [hardware-rev0-base] board = esp32-s3-devkitc-1 @@ -91,12 +91,12 @@ build_src_flags = ${env.build_src_flags} [env:hardware-rev0-it_IT] extends = hardware-rev0-base build_src_flags = ${hardware-rev0-base.build_src_flags} - -D FABLAB_LANG_IT_IT + -D FABOMATIC_LANG_IT_IT [env:hardware-rev0-en_US] extends = hardware-rev0-base build_src_flags = ${hardware-rev0-base.build_src_flags} - -D FABLAB_LANG_EN_US + -D FABOMATIC_LANG_EN_US [env:esp32-devboard] board = esp32dev @@ -106,7 +106,7 @@ build_src_flags = ${env.build_src_flags} -D MQTT_SIMULATION=false -D RFID_SIMULATION=false -D PINS_ESP32 - -D FABLAB_LANG_EN_US + -D FABOMATIC_LANG_EN_US upload_protocol = espota upload_port = board1 @@ -119,7 +119,7 @@ build_src_flags = ${env.build_src_flags} -D MQTT_SIMULATION=true -D RFID_SIMULATION=true -D PINS_WOKWI - -D FABLAB_LANG_EN_US + -D FABOMATIC_LANG_EN_US [env:wrover-kit-it_IT] board = esp-wrover-kit @@ -132,4 +132,4 @@ build_src_flags = ${env.build_src_flags} -D RFID_SIMULATION=true -D PINS_ESP32_WROVERKIT -D DEBUG - -D FABLAB_LANG_IT_IT \ No newline at end of file + -D FABOMATIC_LANG_IT_IT \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 674ea133..feff2dcb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ #include "mock/MockMQTTBroker.hpp" #endif #include "pins.hpp" +#include "language/lang.hpp" // For ArduinoOTA const char *const ssid = fabomatic::secrets::credentials::ssid.data(); @@ -354,9 +355,9 @@ namespace fabomatic config.mqtt_switch_topic.resize(conf::common::STR_MAX_LENGTH); config.machine_id.resize(conf::common::INT_MAX_LENGTH); - WiFiManagerParameter custom_mqtt_server("Broker", "MQTT Broker address", config.mqtt_server.data(), conf::common::STR_MAX_LENGTH); - WiFiManagerParameter custom_mqtt_topic("Topic", "MQTT Switch topic (leave empty to disable)", config.mqtt_switch_topic.data(), conf::common::STR_MAX_LENGTH); - WiFiManagerParameter custom_machine_id("MachineID", "Machine ID", config.machine_id.data(), conf::common::INT_MAX_LENGTH, "type='number' min='0' max='65535'"); + WiFiManagerParameter custom_mqtt_server("Broker", strings::PORTAL_MQTT_BROKER_PROMPT, config.mqtt_server.data(), conf::common::STR_MAX_LENGTH); + WiFiManagerParameter custom_mqtt_topic("Topic", strings::PORTAL_SHELLY_MQTT_PROMPT, config.mqtt_switch_topic.data(), conf::common::STR_MAX_LENGTH); + WiFiManagerParameter custom_machine_id("MachineID", strings::PORTAL_MACHINE_ID_PROMPT, config.machine_id.data(), conf::common::INT_MAX_LENGTH, "type='number' min='0' max='65535'"); wifiManager.addParameter(&custom_mqtt_server); wifiManager.addParameter(&custom_mqtt_topic); @@ -366,7 +367,7 @@ namespace fabomatic wifiManager.setConnectRetries(3); // 3 retries wifiManager.setConnectTimeout(10); // 10 seconds wifiManager.setCountry("IT"); - wifiManager.setTitle("FabLab Bergamo - RFID arduino"); + wifiManager.setTitle(strings::PORTAL_TITLE); wifiManager.setCaptivePortalEnable(true); wifiManager.setAPCallback(configModeCallback); wifiManager.setSaveConfigCallback(saveConfigCallback); diff --git a/src/mock/MockMQTTBroker.cpp b/src/mock/MockMQTTBroker.cpp index d9253b93..50b78d65 100644 --- a/src/mock/MockMQTTBroker.cpp +++ b/src/mock/MockMQTTBroker.cpp @@ -138,11 +138,9 @@ namespace fabomatic << ",\"name\":\"User" << uid_str << "\"}"; return ss.str(); } - else - { - ESP_LOGE(TAG2, "Failed to parse checkuser query"); - return "{\"request_ok\":false}"; - } + + ESP_LOGE(TAG2, "Failed to parse checkuser query"); + return "{\"request_ok\":false}"; } if (query.find("alive") != std::string::npos)