-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from flattermann/i18n
Added Translation support (I18n)
- Loading branch information
Showing
15 changed files
with
456 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "I18n.h" | ||
|
||
String I18n::s_allLanguages[] = ALL_LANGUAGES; | ||
int I18n::s_languageId = DEFAULT_LANGUAGE; | ||
|
||
void I18n::setLanguageId(const int langId) { | ||
s_languageId = langId; | ||
} | ||
|
||
String I18n::getLanguageString(const int langId) { | ||
if (langId >= 0 && langId < LANG_NUM) { | ||
return s_allLanguages[langId]; | ||
} | ||
return "invalid"; | ||
} | ||
|
||
String *I18n::getAllLanguages() { | ||
return s_allLanguages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef I18N_H | ||
#define I18N_H | ||
|
||
#include "config_helper.h" | ||
#include <Arduino.h> | ||
|
||
#define ALL_LANGUAGES {"en", "de", "fr"} | ||
|
||
enum Language { | ||
LANG_EN = 0, | ||
LANG_DE, | ||
LANG_FR, | ||
LANG_NUM // keep this as last item | ||
}; | ||
|
||
#define DEFAULT_LANGUAGE LANG_EN | ||
|
||
class I18n { | ||
public: | ||
static void setLanguageId(int langId); | ||
static String getLanguageString(int langId); | ||
static String *getAllLanguages(); | ||
|
||
template <size_t N> | ||
static const char *get(const char *const (&translations)[N]) { | ||
const char *text = translations[s_languageId]; | ||
if (text == nullptr) { | ||
text = translations[DEFAULT_LANGUAGE]; | ||
} | ||
return text ? text : "@missingTranslation@"; | ||
} | ||
|
||
template <size_t X, size_t Y> | ||
static const char *get(const char *const (&translations)[X][Y], size_t index) { | ||
if (index >= X) { | ||
return "@invalidIndex@"; | ||
} | ||
|
||
const char *text = translations[index][s_languageId]; | ||
if (text == nullptr) { | ||
text = translations[index][DEFAULT_LANGUAGE]; | ||
} | ||
return text ? text : "@missingTranslation@"; | ||
} | ||
|
||
private: | ||
static String s_allLanguages[]; | ||
static int s_languageId; | ||
}; | ||
|
||
// I18n helper | ||
template <size_t N> | ||
static const char *i18n(const char *const (&translations)[N]) { | ||
return I18n::get(translations); | ||
} | ||
|
||
// I18n helper (with index) | ||
template <size_t X, size_t Y> | ||
static const char *i18n(const char *const (&translations)[X][Y], size_t index) { | ||
return I18n::get(translations, index); | ||
} | ||
|
||
#endif // I18N_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include "Translations.h" | ||
|
||
// Languages are defined in I18n.h: | ||
// EN, DE, FR | ||
|
||
// THIS FILE IS ONLY FOR GENERAL TRANSLATIONS | ||
// Widget translations should be placed in a separate .h/.cpp in the Widget directory | ||
|
||
// All translation variables should start with "t_" | ||
|
||
constexpr const char *const t_welcome[LANG_NUM] = { | ||
"Welcome", // EN | ||
"Willkommen", // DE | ||
"Bienvenue" // FR | ||
}; | ||
|
||
constexpr const char *const t_infoOrbs[LANG_NUM] = { | ||
"InfoOrbs", // EN | ||
"InfoOrbs", // DE | ||
"InfoOrbs" // FR | ||
}; | ||
|
||
constexpr const char *const t_by[LANG_NUM] = { | ||
"by", // EN | ||
"von", // DE | ||
"par" // FR | ||
}; | ||
|
||
constexpr const char *const t_brettTech[LANG_NUM] = { | ||
"brett.tech", // EN | ||
"brett.tech", // DE | ||
"brett.tech" // FR | ||
}; | ||
|
||
constexpr const char *const t_version[LANG_NUM] = { | ||
"Version", // EN | ||
"Version", // DE | ||
"Version" // FR | ||
}; | ||
|
||
constexpr const char *const t_loadingData[LANG_NUM] = { | ||
"Loading data:", // EN | ||
"Lade Daten:", // DE | ||
"Chargement:" // FR | ||
}; | ||
|
||
constexpr const char *const t_enableWidget[LANG_NUM] = { | ||
"Enable Widget", // EN | ||
"Widget aktivieren", // DE | ||
"Activer le widget" // FR | ||
}; | ||
|
||
constexpr const char *const t_timezoneLoc[LANG_NUM] = { | ||
"Timezone, use one from <a href='https://timezonedb.com/time-zones' target='blank'>this list</a>", // EN | ||
"Zeitzone, verwenden Sie eine aus <a href='https://timezonedb.com/time-zones' target='blank'>dieser Liste</a>", // DE | ||
"Fuseau horaire, utilisez-en un de <a href='https://timezonedb.com/time-zones' target='blank'>cette liste</a>" // FR | ||
}; | ||
|
||
constexpr const char *const t_language[LANG_NUM] = { | ||
"Language", // EN | ||
"Sprache", // DE | ||
"Langue" // FR | ||
}; | ||
|
||
constexpr const char *const t_widgetCycleDelay[LANG_NUM] = { | ||
"Automatically cycle widgets every X seconds, set to 0 to disable", // EN | ||
"Wechseln Sie die Widgets automatisch alle X Sekunden, auf 0 setzen, um zu deaktivieren", // DE | ||
"Faites défiler les widgets automatiquement toutes les X secondes, définissez sur 0 pour désactiver" // FR | ||
}; | ||
|
||
constexpr const char *const t_ntpServer[LANG_NUM] = { | ||
"NTP server", // EN | ||
"NTP-Server", // DE | ||
"Serveur NTP" // FR | ||
}; | ||
|
||
constexpr const char *const t_orbRotation[LANG_NUM] = { | ||
"Orb rotation", // EN | ||
"Orb-Drehung", // DE | ||
"Rotation des Orbes" // FR | ||
}; | ||
|
||
constexpr const char *const t_orbRot[4][LANG_NUM] = { | ||
{ | ||
"No rotation", // EN | ||
"Keine Drehung", // DE | ||
"Pas de rotation" // FR | ||
}, | ||
{ | ||
"Rotate 90°", // EN | ||
"90° gedreht", // DE | ||
"Tourné de 90°" // FR | ||
}, | ||
{ | ||
"Rotate 180°", // EN | ||
"180° gedreht", // DE | ||
"Tourné de 180°" // FR | ||
}, | ||
{ | ||
"Rotate 270°", // EN | ||
"270° gedreht", // DE | ||
"Tourné de 270°" // FR | ||
}}; | ||
|
||
constexpr const char *const t_nightmode[LANG_NUM] = { | ||
"Enable Nighttime mode", // EN | ||
"Nachtmodus aktivieren", // DE | ||
"Activer le mode nuit" // FR | ||
}; | ||
|
||
constexpr const char *const t_tftBrightness[LANG_NUM] = { | ||
"TFT Brightness [0-255]", // EN | ||
"TFT-Helligkeit [0-255]", // DE | ||
"Luminosité TFT [0-255]" // FR | ||
}; | ||
|
||
constexpr const char *const t_dimStartHour[LANG_NUM] = { | ||
"Nighttime Start [24h format]", // EN | ||
"Nachtmodus Start [24h-Format]", // DE | ||
"Début de la nuit [format 24h]" // FR | ||
}; | ||
|
||
constexpr const char *const t_dimEndHour[LANG_NUM] = { | ||
"Nighttime End [24h format]", // EN | ||
"Nachtmodus Ende [24h-Format]", // DE | ||
"Fin de la nuit [format 24h]" // FR | ||
}; | ||
|
||
constexpr const char *const t_dimBrightness[LANG_NUM] = { | ||
"Nighttime Brightness [0-255]", // EN | ||
"Nachtmodus Helligkeit [0-255]", // DE | ||
"Luminosité nocturne [0-255]" // FR | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef TRANSLATIONS_H | ||
#define TRANSLATIONS_H | ||
|
||
#include "I18n.h" | ||
|
||
// THIS FILE IS ONLY FOR GENERAL TRANSLATIONS | ||
// Widget translations should be placed in a separate .h/.cpp in the Widget directory | ||
|
||
// All translation variables should start with "t_" | ||
|
||
extern const char *const t_welcome[LANG_NUM]; | ||
extern const char *const t_infoOrbs[LANG_NUM]; | ||
extern const char *const t_by[LANG_NUM]; | ||
extern const char *const t_brettTech[LANG_NUM]; | ||
extern const char *const t_version[LANG_NUM]; | ||
extern const char *const t_loadingData[LANG_NUM]; | ||
extern const char *const t_enableWidget[LANG_NUM]; | ||
extern const char *const t_timezoneLoc[LANG_NUM]; | ||
extern const char *const t_language[LANG_NUM]; | ||
extern const char *const t_widgetCycleDelay[LANG_NUM]; | ||
extern const char *const t_ntpServer[LANG_NUM]; | ||
extern const char *const t_orbRotation[LANG_NUM]; | ||
extern const char *const t_orbRot[4][LANG_NUM]; | ||
extern const char *const t_nightmode[LANG_NUM]; | ||
extern const char *const t_tftBrightness[LANG_NUM]; | ||
extern const char *const t_dimStartHour[LANG_NUM]; | ||
extern const char *const t_dimEndHour[LANG_NUM]; | ||
extern const char *const t_dimBrightness[LANG_NUM]; | ||
|
||
#endif // TRANSLATIONS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.