diff --git a/src/plugins/Display/Display.h b/src/plugins/Display/Display.h index b2c88b05..e263d667 100644 --- a/src/plugins/Display/Display.h +++ b/src/plugins/Display/Display.h @@ -9,6 +9,7 @@ #include "../../hm/hmSystem.h" #include "../../hm/hmRadio.h" #include "../../utils/helper.h" +#include "../plugin_lang.h" #include "Display_Mono.h" #include "Display_Mono_128X32.h" #include "Display_Mono_128X64.h" diff --git a/src/plugins/Display/Display_Mono_128X64.h b/src/plugins/Display/Display_Mono_128X64.h index c63f0b22..45e07e6f 100644 --- a/src/plugins/Display/Display_Mono_128X64.h +++ b/src/plugins/Display/Display_Mono_128X64.h @@ -93,7 +93,7 @@ class DisplayMono128X64 : public DisplayMono { // print Date and time if (0 != mDisplayData->utcTs) - printText(ah::getDateTimeStrShort(mDisplayData->utcTs).c_str(), l_Time, 0xff); + printText(ah::getDateTimeStrShort_i18n(mDisplayData->utcTs).c_str(), l_Time, 0xff); if (showLine(l_Status)) { // alternatively: @@ -145,7 +145,7 @@ class DisplayMono128X64 : public DisplayMono { printText(mFmtText, l_TotalPower, 0xff); } else { - printText("offline", l_TotalPower, 0xff); + printText(STR_OFFLINE, l_TotalPower, 0xff); } } diff --git a/src/plugins/Display/Display_Mono_84X48.h b/src/plugins/Display/Display_Mono_84X48.h index b5daacd5..75a11207 100644 --- a/src/plugins/Display/Display_Mono_84X48.h +++ b/src/plugins/Display/Display_Mono_84X48.h @@ -78,7 +78,7 @@ class DisplayMono84X48 : public DisplayMono { // print Date and time if (0 != mDisplayData->utcTs) - printText(ah::getDateTimeStrShort(mDisplayData->utcTs).c_str(), l_Time, 0xff); + printText(ah::getDateTimeStrShort_i18n(mDisplayData->utcTs).c_str(), l_Time, 0xff); if (showLine(l_Status)) { // alternatively: @@ -111,7 +111,7 @@ class DisplayMono84X48 : public DisplayMono { printText(mFmtText, l_TotalPower, 0xff); } else { - printText("offline", l_TotalPower, 0xff); + printText(STR_OFFLINE, l_TotalPower, 0xff); } } diff --git a/src/plugins/plugin_lang.h b/src/plugins/plugin_lang.h new file mode 100644 index 00000000..a5866af9 --- /dev/null +++ b/src/plugins/plugin_lang.h @@ -0,0 +1,18 @@ +//----------------------------------------------------------------------------- +// 2024 Ahoy, https://ahoydtu.de +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed +//----------------------------------------------------------------------------- + +#ifndef __PLUGIN_LANG_H__ +#define __PLUGIN_LANG_H__ +#ifdef LANG_DE + #define STR_MONTHNAME_3_CHAR_LIST "ErrJanFebMrzAprMaiJunJulAugSepOktNovDez" + #define STR_DAYNAME_3_CHAR_LIST "ErrSonMonDieMitDonFreSam" + #define STR_OFFLINE "-- AUS --" +#else + #define STR_MONTHNAME_3_CHAR_LIST "ErrJanFebMarAprMayJunJulAugSepOctNovDec" + #define STR_DAYNAME_3_CHAR_LIST "ErrSunMonTueWedThuFriSat" + #define STR_OFFLINE "offline" +#endif + +#endif /*__PLUGIN_LANG_H__*/ \ No newline at end of file diff --git a/src/utils/helper.cpp b/src/utils/helper.cpp index 24a4d9ee..d5612e56 100644 --- a/src/utils/helper.cpp +++ b/src/utils/helper.cpp @@ -5,6 +5,7 @@ #include "helper.h" #include "dbg.h" +#include "../plugins/plugin_lang.h" namespace ah { void ip2Arr(uint8_t ip[], const char *ipStr) { @@ -82,6 +83,37 @@ namespace ah { return String(str); } + #define dt_SHORT_STR_LEN_i18n 3 // the length of short strings + static char buffer[dt_SHORT_STR_LEN_i18n + 1]; // must be big enough for longest string and the terminating null + const char monthShortNames_P[] PROGMEM = STR_MONTHNAME_3_CHAR_LIST; + const char dayShortNames_P[] PROGMEM = STR_DAYNAME_3_CHAR_LIST; + char* monthShortStr_i18n(uint8_t month) + { + for (int i=0; i < dt_SHORT_STR_LEN_i18n; i++) + buffer[i] = pgm_read_byte(&(monthShortNames_P[i + month * dt_SHORT_STR_LEN_i18n])); + buffer[dt_SHORT_STR_LEN_i18n] = 0; + return buffer; + } + + char* dayShortStr_i18n(uint8_t day) + { + for (int i=0; i < dt_SHORT_STR_LEN_i18n; i++) + buffer[i] = pgm_read_byte(&(dayShortNames_P[i + day * dt_SHORT_STR_LEN_i18n])); + buffer[dt_SHORT_STR_LEN_i18n] = 0; + return buffer; + } + + String getDateTimeStrShort_i18n(time_t t) { + char str[20]; + if(0 == t) + sprintf(str, "n/a"); + else { + sprintf(str, "%3s ", dayShortStr_i18n(dayOfWeek(t))); + sprintf(str+4, "%2d.%3s %02d:%02d", day(t), monthShortStr_i18n(month(t)), hour(t), minute(t)); + } + return String(str); + } + uint64_t Serial2u64(const char *val) { char tmp[3]; uint64_t ret = 0ULL; diff --git a/src/utils/helper.h b/src/utils/helper.h index 1dbba3d9..80a63f41 100644 --- a/src/utils/helper.h +++ b/src/utils/helper.h @@ -42,6 +42,7 @@ namespace ah { double round3(double value); String getDateTimeStr(time_t t); String getDateTimeStrShort(time_t t); + String getDateTimeStrShort_i18n(time_t t); String getDateTimeStrFile(time_t t); String getTimeStr(time_t t); String getTimeStrMs(uint64_t t);