fix REST-API - strange characters in http://<hostname>/api/<device>/commands output #671

This commit is contained in:
Proddy
2022-10-09 14:18:29 +02:00
parent 324d27896b
commit 8d6c676fed
6 changed files with 25 additions and 7 deletions

View File

@@ -719,4 +719,21 @@ std::string Helpers::translated_word(const char * const * strings, bool to_lower
return to_lower ? toLower((strings[index])) : (strings[index]);
}
// returns char pointer to translated description or fullname
const char * Helpers::translated_fullname(const char * const * strings) {
uint8_t language_index = EMSESP::system_.language_index();
uint8_t index = 0;
// check for empty
if (!strings) {
return nullptr; // it's a nullptr with no translations, return empty to prevent unwanted crash
}
// see how many translations we have for this entity. if there is no translation for this, revert to EN
if (Helpers::count_items(strings) >= language_index + 1 && strlen(strings[language_index])) {
index = language_index;
}
return strings[index];
}
} // namespace emsesp