-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfallback_and_format.ino
More file actions
61 lines (47 loc) · 1.39 KB
/
Copy pathfallback_and_format.ino
File metadata and controls
61 lines (47 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <Arduino.h>
#include <ESPLang.h>
namespace AppLanguage {
static constexpr LangLanguageId EN = 1;
static constexpr LangLanguageId HU = 2;
} // namespace AppLanguage
enum class AppText : uint16_t {
BatteryLow = 1,
DoorOpen = 2,
};
static const LangTranslationEntry kEnglish[] = {
ESP_LANG_ENTRY(AppText::BatteryLow, "Battery low: %d%%"),
ESP_LANG_ENTRY(AppText::DoorOpen, "Door is open"),
};
static const LangTranslationEntry kHungarian[] = {
ESP_LANG_ENTRY(AppText::BatteryLow, "Alacsony akkuszint: %d%%"),
};
static const LangTranslationTable kTables[] = {
makeLangTable(AppLanguage::EN, kEnglish),
makeLangTable(AppLanguage::HU, kHungarian),
};
ESPLang lang;
void setup() {
Serial.begin(115200);
ESPLangConfig config{};
config.tables = kTables;
config.tableCount = sizeof(kTables) / sizeof(kTables[0]);
config.defaultLanguage = AppLanguage::EN;
config.useDefaultFallback = false;
config.fallbackLanguage = AppLanguage::EN;
config.missingText = "[missing]";
if (!lang.init(config)) {
Serial.println("ESPLang init failed");
return;
}
lang.setLanguage(AppLanguage::HU);
char buffer[48];
if (lang.format(buffer, sizeof(buffer), AppText::BatteryLow, 17)) {
Serial.println(buffer);
}
Serial.println(lang.translate(AppText::DoorOpen));
lang.setMissingText("N/A");
Serial.println(lang.translate(static_cast<LangKeyId>(999)));
}
void loop() {
delay(1000);
}